Make findDOMNode error clearer
Fixes #4233.
Ben Alpert committed
Aug 24, 2015 at 16:15 UTC
6a2cdd58a4760e82f1f8e8a45e4f62b28b6f9c84
2 files changed
+14
-9
src/renderers/dom/client/__tests__/findDOMNode-test.js
+13
-6
@@ -44,12 +44,19 @@ describe('findDOMNode', function() {
44
});
45
46
it('findDOMNode should reject unmounted objects with render func', function() {
47
- expect(function() {
48
- ReactDOM.findDOMNode({render: function() {}});
49
- })
50
- .toThrow('Invariant Violation: Component (with keys: render) ' +
51
- 'contains `render` method but is not mounted in the DOM'
52
- );
47
+ var Foo = React.createClass({
48
+ render: function() {
49
+ return <div />;
50
+ },
51
+ });
52
+
53
+ var container = document.createElement('div');
54
+ var inst = ReactDOM.render(<Foo />, container);
55
+ ReactDOM.unmountComponentAtNode(container);
56
+
57
+ expect(() => ReactDOM.findDOMNode(inst)).toThrow(
58
+ 'Invariant Violation: findDOMNode was called on an unmounted component.'
59
+ );
60
});
61
62
});
src/renderers/dom/client/findDOMNode.js
+1
-3
@@ -53,9 +53,7 @@ function findDOMNode(componentOrElement) {
53
invariant(
54
componentOrElement.render == null ||
55
typeof componentOrElement.render !== 'function',
56
- 'Component (with keys: %s) contains `render` method ' +
57
- 'but is not mounted in the DOM',
58
- Object.keys(componentOrElement)
56
+ 'findDOMNode was called on an unmounted component.'
57
);
58
invariant(
59
false,