Skip to content

Commit 53c3212

Browse files
committed
Test that lifecycles are reverted in reverse order
1 parent c9a9872 commit 53c3212

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

src/renderers/shared/stack/reconciler/__tests__/ReactErrorBoundaries-test.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -709,19 +709,40 @@ describe('ReactErrorBoundaries', () => {
709709
var container = document.createElement('div');
710710
ReactDOM.render(
711711
<ErrorBoundary>
712+
<Normal>
713+
<Normal logName="NormalChild" />
714+
</Normal>
712715
<BrokenComponentDidMount />
716+
<Normal logName="NeverFullyMounted" />
713717
</ErrorBoundary>,
714718
container
715719
);
716720
expect(log).toEqual([
717721
'ErrorBoundary constructor',
718722
'ErrorBoundary componentWillMount',
719723
'ErrorBoundary render success',
724+
'Normal constructor',
725+
'Normal componentWillMount',
726+
'Normal render',
727+
'NormalChild constructor',
728+
'NormalChild componentWillMount',
729+
'NormalChild render',
720730
'BrokenComponentDidMount constructor',
721731
'BrokenComponentDidMount componentWillMount',
722732
'BrokenComponentDidMount render',
733+
'NeverFullyMounted constructor',
734+
'NeverFullyMounted componentWillMount',
735+
'NeverFullyMounted render',
736+
// Start flushing didMount queue
737+
'NormalChild componentDidMount',
738+
'Normal componentDidMount',
723739
'BrokenComponentDidMount componentDidMount [!]',
740+
// Call willUnmount for every didMount so far
724741
'BrokenComponentDidMount componentWillUnmount',
742+
// Parents get willUnmount first
743+
'Normal componentWillUnmount',
744+
'NormalChild componentWillUnmount',
745+
// We didn't need to call willUnmount for NeverFullyMounted.
725746
'ErrorBoundary unstable_handleError',
726747
'ErrorBoundary constructor',
727748
'ErrorBoundary componentWillMount',
@@ -743,7 +764,11 @@ describe('ReactErrorBoundaries', () => {
743764
expect(() => {
744765
ReactDOM.render(
745766
<ErrorBoundary>
767+
<Normal>
768+
<Normal logName="NormalChild" />
769+
</Normal>
746770
<BrokenComponentDidMount />
771+
<Normal logName="NeverFullyMounted" />
747772
</ErrorBoundary>,
748773
container
749774
);
@@ -752,19 +777,23 @@ describe('ReactErrorBoundaries', () => {
752777
'ErrorBoundary constructor',
753778
'ErrorBoundary componentWillMount',
754779
'ErrorBoundary render success',
780+
'Normal constructor',
781+
'Normal componentWillMount',
782+
'Normal render',
783+
'NormalChild constructor',
784+
'NormalChild componentWillMount',
785+
'NormalChild render',
755786
'BrokenComponentDidMount constructor',
756787
'BrokenComponentDidMount componentWillMount',
757788
'BrokenComponentDidMount render',
789+
'NeverFullyMounted constructor',
790+
'NeverFullyMounted componentWillMount',
791+
'NeverFullyMounted render',
792+
'NormalChild componentDidMount',
793+
'Normal componentDidMount',
758794
'BrokenComponentDidMount componentDidMount [!]',
759795
// The error doesn't get caught. :-(
760796
]);
761-
762-
log.length = 0;
763-
ReactDOM.unmountComponentAtNode(container);
764-
expect(log).toEqual([
765-
'ErrorBoundary componentWillUnmount',
766-
'BrokenComponentDidMount componentWillUnmount',
767-
]);
768797
});
769798
}
770799

0 commit comments

Comments
 (0)