Skip to content
Merged
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOM-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,26 @@ describe('ReactDOM', () => {
}
});

it('should not throw a TypeError when reading stateNode on ReactCurrentOwner', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We avoid implementation details in test titles. Just "should not crash calling findDOMNode inside a functional component".

class Component extends React.Component {
render() {
return <div />;
}
}

const App = () => ReactDOM.findDOMNode(Component);
const container = document.createElement('div');
const stateNodeErr = new TypeError(
"Cannot read property '_warnedAboutRefsInRender' of null",
);

if (__DEV__) {
expect(() => {
ReactDOM.render(<App />, container);
}).not.toThrow(stateNodeErr);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's enough to replace this whole block with just ReactDOM.render(<App />, container). If it did throw, the test would fail anyway. You can remove the error declaration too.

});

it('throws in DEV if jsdom is destroyed by the time setState() is called', () => {
class App extends React.Component {
state = {x: 1};
Expand Down