Merge pull request #4727 from spicyj/gh-4233

Make findDOMNode error clearer
This commit is contained in:
Ben Alpert
2015-08-28 12:52:18 -07:00
2 changed files with 14 additions and 9 deletions
@@ -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.'
);
});
});
+1 -3
View File
@@ -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,