diff --git a/src/renderers/shared/stack/reconciler/__tests__/ReactErrorBoundaries-test.js b/src/renderers/shared/stack/reconciler/__tests__/ReactErrorBoundaries-test.js index c61d1f524dab1..960bc13279cc6 100644 --- a/src/renderers/shared/stack/reconciler/__tests__/ReactErrorBoundaries-test.js +++ b/src/renderers/shared/stack/reconciler/__tests__/ReactErrorBoundaries-test.js @@ -13,13 +13,11 @@ var React; var ReactDOM; -var ReactDOMServer; describe('ReactErrorBoundaries', function() { beforeEach(function() { ReactDOM = require('ReactDOM'); - ReactDOMServer = require('ReactDOMServer'); React = require('React'); }); @@ -37,9 +35,11 @@ describe('ReactErrorBoundaries', function() { } render() { if (!this.state.error) { - return (
); + return ( +
+ ); } else { - return (
Happy Birthday!
); + return
Happy Birthday!
; } } onClick() { @@ -57,11 +57,19 @@ describe('ReactErrorBoundaries', function() { expect(EventPluginHub.putListener).not.toBeCalled(); }); - it('renders an error state (ssr)', function() { + it('renders an error state', function() { + var log = []; class Angry extends React.Component { render() { + log.push('Angry render'); throw new Error('Please, do not render me.'); } + componentDidMount() { + log.push('Angry componentDidMount'); + } + componentWillUnmount() { + log.push('Angry componentWillUnmount'); + } } class Boundary extends React.Component { @@ -70,12 +78,21 @@ describe('ReactErrorBoundaries', function() { this.state = {error: false}; } render() { + log.push('Boundary render'); if (!this.state.error) { - return (
); + return ( +
+ ); } else { - return (
Happy Birthday!
); + return
Happy Birthday!
; } } + componentDidMount() { + log.push('Boundary componentDidMount'); + } + componentWillUnmount() { + log.push('Boundary componentWillUnmount'); + } onClick() { /* do nothing */ } @@ -84,12 +101,15 @@ describe('ReactErrorBoundaries', function() { } } - var EventPluginHub = require('EventPluginHub'); var container = document.createElement('div'); - EventPluginHub.putListener = jest.fn(); - container.innerHTML = ReactDOMServer.renderToString(); + ReactDOM.render(, container); expect(container.firstChild.innerHTML).toBe('Happy Birthday!'); - expect(EventPluginHub.putListener).not.toBeCalled(); + expect(log).toEqual([ + 'Boundary render', + 'Angry render', + 'Boundary render', + 'Boundary componentDidMount', + ]); }); it('will catch exceptions in componentWillUnmount', function() { @@ -98,14 +118,14 @@ describe('ReactErrorBoundaries', function() { super(); this.state = {error: false}; } - + render() { if (!this.state.error) { return
{this.props.children}
; } return
Error has been caught
; } - + unstable_handleError() { this.setState({error: true}); } @@ -139,27 +159,36 @@ describe('ReactErrorBoundaries', function() { }); it('expect uneventful render to succeed', function() { + var log = []; class Boundary extends React.Component { constructor(props) { super(props); this.state = {error: false}; } render() { - return (
); + log.push('Boundary render'); + return
; } onClick() { /* do nothing */ } + componentDidMount() { + log.push('Boundary componentDidMount'); + } + componentWillUnmount() { + log.push('Boundary componentWillUnmount'); + } unstable_handleError() { this.setState({error: true}); } } - var EventPluginHub = require('EventPluginHub'); var container = document.createElement('div'); - EventPluginHub.putListener = jest.fn(); ReactDOM.render(, container); - expect(EventPluginHub.putListener).toBeCalled(); + expect(log).toEqual([ + 'Boundary render', + 'Boundary componentDidMount', + ]); }); it('correctly handles composite siblings', function() { @@ -168,14 +197,14 @@ describe('ReactErrorBoundaries', function() { super(); this.state = {error: false}; } - + render() { if (!this.state.error) { return
{this.props.children}
; } return
Error has been caught
; } - + unstable_handleError() { this.setState({error: true}); } diff --git a/src/renderers/testing/__tests__/ReactTestRenderer-test.js b/src/renderers/testing/__tests__/ReactTestRenderer-test.js index 9e938242d9424..e562867fd2dbb 100644 --- a/src/renderers/testing/__tests__/ReactTestRenderer-test.js +++ b/src/renderers/testing/__tests__/ReactTestRenderer-test.js @@ -207,10 +207,18 @@ describe('ReactTestRenderer', function() { }); it('supports error boundaries', function() { + var log = []; class Angry extends React.Component { render() { + log.push('Angry render'); throw new Error('Please, do not render me.'); } + componentDidMount() { + log.push('Angry componentDidMount'); + } + componentWillUnmount() { + log.push('Angry componentWillUnmount'); + } } class Boundary extends React.Component { @@ -219,12 +227,21 @@ describe('ReactTestRenderer', function() { this.state = {error: false}; } render() { + log.push('Boundary render'); if (!this.state.error) { - return (
); + return ( +
+ ); } else { - return (
Happy Birthday!
); + return
Happy Birthday!
; } } + componentDidMount() { + log.push('Boundary componentDidMount'); + } + componentWillUnmount() { + log.push('Boundary componentWillUnmount'); + } onClick() { /* do nothing */ } @@ -233,15 +250,18 @@ describe('ReactTestRenderer', function() { } } - var EventPluginHub = require('EventPluginHub'); - EventPluginHub.putListener = jest.fn(); var renderer = ReactTestRenderer.create(); expect(renderer.toJSON()).toEqual({ type: 'div', props: {}, children: ['Happy Birthday!'], }); - expect(EventPluginHub.putListener).not.toBeCalled(); + expect(log).toEqual([ + 'Boundary render', + 'Angry render', + 'Boundary render', + 'Boundary componentDidMount', + ]); }); });