Skip to content

Commit 6a2cdd5

Browse files
committed
Make findDOMNode error clearer
Fixes facebook#4233.
1 parent b38509c commit 6a2cdd5

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/renderers/dom/client/__tests__/findDOMNode-test.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,19 @@ describe('findDOMNode', function() {
4444
});
4545

4646
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+
);
5360
});
5461

5562
});

src/renderers/dom/client/findDOMNode.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ function findDOMNode(componentOrElement) {
5353
invariant(
5454
componentOrElement.render == null ||
5555
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.'
5957
);
6058
invariant(
6159
false,

0 commit comments

Comments
 (0)