From 712a7bd6d8405bfa1986e20a81b220a71503ab01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 7 Dec 2016 10:31:32 +0100 Subject: [PATCH 1/3] [react-test-renderer] unmount the inner instances Fixes https://github.com/facebook/react/issues/8459 --- src/renderers/testing/ReactTestRenderer.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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); From e580e6a4aa180033da41d2f217cac4285d35863f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 7 Dec 2016 10:36:27 +0100 Subject: [PATCH 2/3] add a test for https://github.com/facebook/react/issues/8459 --- .../__tests__/ReactTestRenderer-test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 => { From 625d1fa0593b8d11bfda37cf8c9391c9e4d96c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Fri, 9 Dec 2016 18:00:49 +0100 Subject: [PATCH 3/3] add new test in tests-passing.txt --- scripts/fiber/tests-passing.txt | 1 + 1 file changed, 1 insertion(+) 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