Fix test renderer unmount (#8512)
* [react-test-renderer] unmount the inner instances Fixes https://github.com/facebook/react/issues/8459 * add a test for https://github.com/facebook/react/issues/8459 * add new test in tests-passing.txt
Gaëtan Renaudeau committed
Dec 14, 2016 at 16:57 UTC
931cad5aae77659332ec771c124258edf139d568
3 files changed
+23
-1
scripts/fiber/tests-passing.txt
+1
@@ -1589,6 +1589,7 @@ src/renderers/testing/__tests__/ReactTestRenderer-test.js
1589
* warns correctly for refs on SFCs
1590
* allows an optional createNodeMock function
1591
* supports unmounting when using refs
1592
+* supports unmounting inner instances
1593
* supports updates when using refs
1594
* supports error boundaries
1595
src/renderers/testing/ReactTestRenderer.js
+4
-1
@@ -121,7 +121,10 @@ class ReactTestComponent {
121
}
122
123
getHostNode(): void {}
124
- unmountComponent(): void {}
124
+ unmountComponent(safely, skipLifecycle): void {
125
+ // $FlowFixMe https://github.com/facebook/flow/issues/1805
126
+ this.unmountChildren(safely, skipLifecycle);
127
+ }
128
}
129
130
Object.assign(ReactTestComponent.prototype, ReactMultiChild);
src/renderers/testing/__tests__/ReactTestRenderer-test.js
+18
@@ -326,6 +326,24 @@ describe('ReactTestRenderer', () => {
326
expect(() => inst.unmount()).not.toThrow();
327
});
328
329
+ it('supports unmounting inner instances', () => {
330
+ let count = 0;
331
+ class Foo extends React.Component {
332
+ componentWillUnmount() {
333
+ count++;
334
+ }
335
+ render() {
336
+ return <div />;
337
+ }
338
+ }
339
+ const inst = ReactTestRenderer.create(
340
+ <div><Foo /></div>,
341
+ {createNodeMock: () => 'foo'}
342
+ );
343
+ expect(() => inst.unmount()).not.toThrow();
344
+ expect(count).toEqual(1);
345
+ });
346
+
347
it('supports updates when using refs', () => {
348
const log = [];
349
const createNodeMock = element => {