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

[ReactDOM] Add strict mode test for findDOMNode #15091

Closed
Closed
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
22 changes: 22 additions & 0 deletions packages/react-dom/src/__tests__/findDOMNode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,26 @@ describe('findDOMNode', () => {
]);
expect(match).toBe(child);
});

it('findDOMNode should not warn if passed a host component inside StrictMode', () => {
let child = undefined;

class IsInStrictMode extends React.Component {
render() {
const {as: Component} = this.props;
return <Component ref={n => (child = n)} />;
}
}

ReactTestUtils.renderIntoDocument(
<StrictMode>
<IsInStrictMode as="span" />
</StrictMode>,
);

// outside of dev toWarnDev would always pass which means negating it would always fail
if (__DEV__) {
expect(() => ReactDOM.findDOMNode(child)).not.toWarnDev(['**']);
Copy link
Collaborator Author

@eps1lon eps1lon Mar 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this also match a potential future warning? I had the full message originally but I'm not sure how it would actually look like

Suggested change
expect(() => ReactDOM.findDOMNode(child)).not.toWarnDev(['**']);
expect(() => ReactDOM.findDOMNode(child)).not.toWarnDev(['Warning: findDOMNode is deprecated in StrictMode.**']);

}
});
});