mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #4727 from spicyj/gh-4233
Make findDOMNode error clearer
This commit is contained in:
@@ -44,12 +44,19 @@ describe('findDOMNode', function() {
|
||||
});
|
||||
|
||||
it('findDOMNode should reject unmounted objects with render func', function() {
|
||||
expect(function() {
|
||||
ReactDOM.findDOMNode({render: function() {}});
|
||||
})
|
||||
.toThrow('Invariant Violation: Component (with keys: render) ' +
|
||||
'contains `render` method but is not mounted in the DOM'
|
||||
);
|
||||
var Foo = React.createClass({
|
||||
render: function() {
|
||||
return <div />;
|
||||
},
|
||||
});
|
||||
|
||||
var container = document.createElement('div');
|
||||
var inst = ReactDOM.render(<Foo />, container);
|
||||
ReactDOM.unmountComponentAtNode(container);
|
||||
|
||||
expect(() => ReactDOM.findDOMNode(inst)).toThrow(
|
||||
'Invariant Violation: findDOMNode was called on an unmounted component.'
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -53,9 +53,7 @@ function findDOMNode(componentOrElement) {
|
||||
invariant(
|
||||
componentOrElement.render == null ||
|
||||
typeof componentOrElement.render !== 'function',
|
||||
'Component (with keys: %s) contains `render` method ' +
|
||||
'but is not mounted in the DOM',
|
||||
Object.keys(componentOrElement)
|
||||
'findDOMNode was called on an unmounted component.'
|
||||
);
|
||||
invariant(
|
||||
false,
|
||||
|
||||
Reference in New Issue
Block a user