Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a passing test for unmounting behavior on crashed tree
  • Loading branch information
gaearon committed Nov 30, 2016
commit c1f2eb201b10832076c676102b0e61d872d721d4
1 change: 1 addition & 0 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,7 @@ src/renderers/shared/fiber/__tests__/ReactIncrementalErrorHandling-test.js
* catches reconciler errors in a boundary during mounting
* catches reconciler errors in a boundary during update
* recovers from uncaught reconciler errors
* unmounts components with uncaught errors

src/renderers/shared/fiber/__tests__/ReactIncrementalReflection-test.js
* handles isMounted even when the initial render is deferred
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,4 +812,56 @@ describe('ReactIncrementalErrorHandling', () => {
ReactNoop.flush();
expect(ReactNoop.getChildren()).toEqual([span('hi')]);
});

it('unmounts components with uncaught errors', () => {
const ops = [];
let inst;

class BrokenRenderAndUnmount extends React.Component {
state = {fail: false};
componentWillUnmount() {
ops.push('BrokenRenderAndUnmount componentWillUnmount');
}
render() {
inst = this;
if (this.state.fail) {
throw new Error('Hello.');
}
return null;
}
}

class Parent extends React.Component {
componentWillUnmount() {
ops.push('Parent componentWillUnmount [!]');
throw new Error('One does not simply unmount me.');
}
render() {
return this.props.children;
}
}

ReactNoop.render(
<Parent>
<Parent>
<BrokenRenderAndUnmount />
</Parent>
</Parent>
);
ReactNoop.flush();

inst.setState({fail: true});
expect(() => {
ReactNoop.flush();
}).toThrowError('Hello.');

expect(ops).toEqual([
// Attempt to clean up.
// Errors in parents shouldn't stop children from unmounting.
'Parent componentWillUnmount [!]',
'Parent componentWillUnmount [!]',
'BrokenRenderAndUnmount componentWillUnmount',
]);
expect(ReactNoop.getChildren()).toEqual([]);
});
});