Skip to content

Commit

Permalink
Test that lifecycles are reverted in reverse order
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Oct 26, 2016
1 parent c9a9872 commit 53c3212
Showing 1 changed file with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -709,19 +709,40 @@ describe('ReactErrorBoundaries', () => {
var container = document.createElement('div');
ReactDOM.render(
<ErrorBoundary>
<Normal>
<Normal logName="NormalChild" />
</Normal>
<BrokenComponentDidMount />
<Normal logName="NeverFullyMounted" />
</ErrorBoundary>,
container
);
expect(log).toEqual([
'ErrorBoundary constructor',
'ErrorBoundary componentWillMount',
'ErrorBoundary render success',
'Normal constructor',
'Normal componentWillMount',
'Normal render',
'NormalChild constructor',
'NormalChild componentWillMount',
'NormalChild render',
'BrokenComponentDidMount constructor',
'BrokenComponentDidMount componentWillMount',
'BrokenComponentDidMount render',
'NeverFullyMounted constructor',
'NeverFullyMounted componentWillMount',
'NeverFullyMounted render',
// Start flushing didMount queue
'NormalChild componentDidMount',
'Normal componentDidMount',
'BrokenComponentDidMount componentDidMount [!]',
// Call willUnmount for every didMount so far
'BrokenComponentDidMount componentWillUnmount',
// Parents get willUnmount first
'Normal componentWillUnmount',
'NormalChild componentWillUnmount',
// We didn't need to call willUnmount for NeverFullyMounted.
'ErrorBoundary unstable_handleError',
'ErrorBoundary constructor',
'ErrorBoundary componentWillMount',
Expand All @@ -743,7 +764,11 @@ describe('ReactErrorBoundaries', () => {
expect(() => {
ReactDOM.render(
<ErrorBoundary>
<Normal>
<Normal logName="NormalChild" />
</Normal>
<BrokenComponentDidMount />
<Normal logName="NeverFullyMounted" />
</ErrorBoundary>,
container
);
Expand All @@ -752,19 +777,23 @@ describe('ReactErrorBoundaries', () => {
'ErrorBoundary constructor',
'ErrorBoundary componentWillMount',
'ErrorBoundary render success',
'Normal constructor',
'Normal componentWillMount',
'Normal render',
'NormalChild constructor',
'NormalChild componentWillMount',
'NormalChild render',
'BrokenComponentDidMount constructor',
'BrokenComponentDidMount componentWillMount',
'BrokenComponentDidMount render',
'NeverFullyMounted constructor',
'NeverFullyMounted componentWillMount',
'NeverFullyMounted render',
'NormalChild componentDidMount',
'Normal componentDidMount',
'BrokenComponentDidMount componentDidMount [!]',
// The error doesn't get caught. :-(
]);

log.length = 0;
ReactDOM.unmountComponentAtNode(container);
expect(log).toEqual([
'ErrorBoundary componentWillUnmount',
'BrokenComponentDidMount componentWillUnmount',
]);
});
}

Expand Down

0 comments on commit 53c3212

Please sign in to comment.