Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test renderer unmount #8512

Merged
merged 3 commits into from
Dec 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

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