diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index a1401beb4089c..16c3ae4b48836 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -1552,6 +1552,7 @@ src/renderers/testing/__tests__/ReactTestRenderer-test.js * warns correctly for refs on SFCs * allows an optional createNodeMock function * supports unmounting when using refs +* supports unmounting inner instances * supports updates when using refs * supports error boundaries diff --git a/src/renderers/testing/ReactTestRenderer.js b/src/renderers/testing/ReactTestRenderer.js index 4c20d494a271a..cca77d38353a4 100644 --- a/src/renderers/testing/ReactTestRenderer.js +++ b/src/renderers/testing/ReactTestRenderer.js @@ -121,7 +121,10 @@ class ReactTestComponent { } getHostNode(): void {} - unmountComponent(): void {} + unmountComponent(safely, skipLifecycle): void { + // $FlowFixMe https://github.com/facebook/flow/issues/1805 + this.unmountChildren(safely, skipLifecycle); + } } Object.assign(ReactTestComponent.prototype, ReactMultiChild); diff --git a/src/renderers/testing/__tests__/ReactTestRenderer-test.js b/src/renderers/testing/__tests__/ReactTestRenderer-test.js index 7949e580ca90b..2333095d9631e 100644 --- a/src/renderers/testing/__tests__/ReactTestRenderer-test.js +++ b/src/renderers/testing/__tests__/ReactTestRenderer-test.js @@ -326,6 +326,24 @@ describe('ReactTestRenderer', () => { expect(() => inst.unmount()).not.toThrow(); }); + it('supports unmounting inner instances', () => { + let count = 0; + class Foo extends React.Component { + componentWillUnmount() { + count++; + } + render() { + return
; + } + } + const inst = ReactTestRenderer.create( +
, + {createNodeMock: () => 'foo'} + ); + expect(() => inst.unmount()).not.toThrow(); + expect(count).toEqual(1); + }); + it('supports updates when using refs', () => { const log = []; const createNodeMock = element => {