Skip to content

Commit

Permalink
Fix test renderer unmount (#8512)
Browse files Browse the repository at this point in the history
* [react-test-renderer] unmount the inner instances

Fixes #8459

* add a test for #8459

* add new test in tests-passing.txt
  • Loading branch information
gre authored and aweary committed Dec 14, 2016
1 parent 3def431 commit 931cad5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,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

Expand Down
5 changes: 4 additions & 1 deletion src/renderers/testing/ReactTestRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions src/renderers/testing/__tests__/ReactTestRenderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <div />;
}
}
const inst = ReactTestRenderer.create(
<div><Foo /></div>,
{createNodeMock: () => 'foo'}
);
expect(() => inst.unmount()).not.toThrow();
expect(count).toEqual(1);
});

it('supports updates when using refs', () => {
const log = [];
const createNodeMock = element => {
Expand Down

0 comments on commit 931cad5

Please sign in to comment.