From 70de7e4a38a2c49546666a41741f3cff5484fbc7 Mon Sep 17 00:00:00 2001 From: Maher Beg Date: Sun, 20 Mar 2016 18:31:19 -0700 Subject: [PATCH] Test to verify findDOMNode does not throw in willMount Adds a test to prevent a regression of throwing an error when calling `findDOMNode(this)` in a component's `componentWillMount` function. This previously used to throw an invariant violation but now does not any more. --- .../dom/client/__tests__/findDOMNode-test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/renderers/dom/client/__tests__/findDOMNode-test.js b/src/renderers/dom/client/__tests__/findDOMNode-test.js index cdcc780683..1f861dd345 100644 --- a/src/renderers/dom/client/__tests__/findDOMNode-test.js +++ b/src/renderers/dom/client/__tests__/findDOMNode-test.js @@ -58,4 +58,17 @@ describe('findDOMNode', function() { ); }); + it('findDOMNode should not throw an error when called within a component that is not mounted', function() { + var Bar = React.createClass({ + componentWillMount: function() { + expect(ReactDOM.findDOMNode(this)).toBeNull(); + }, + render: function() { + return
; + }, + }); + + expect(() => ReactTestUtils.renderIntoDocument()).not.toThrow(); + }); + });