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 Brian Vaughn committed Mar 28, 2017
1 parent ac53db3 commit 17434d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/renderers/testing/ReactTestRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,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.Mixin);
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 17434d7

Please sign in to comment.