React 13.3 unmountComponentAtNode () Error: target container is not a DOM element

I get the following error in my test suite when I upgrade from React 12.2 to React 13.3:

Error: Invariant violation: unmountComponentAtNode (...): Target container is not a DOM element.

I use this blog post to test my code with Jasmine. An error occurs in this code:

describe("A component", function() { var instance; var container = document.createElement("div"); afterEach(function() { if (instance && instance.isMounted()) { // Only components with a parent will be unmounted React.unmountComponentAtNode(instance.getDOMNode().parent); } }); ...rest of test suite... // the instances of renderIntoDocument that cause the failure look like the below it("Causes my test suite to fail.", function() { instance = TestUtils.renderIntoDocument(<MyReactElement/>); }); )}; 

I know getDOMNode() deprecated, but that is not what causes the error.

When I check instance.getDOMNode() , it returns the given instance, but when it is wrong, instance.getDOMNode().parent is undefined. Calling React.unmountComponentAtNode on this undefined variable throws an error.

The answers to this suggest that there is some kind of race condition, but I'm not sure how this applies to my test suite. Thanks for any help!

+5
source share
1 answer

The fix should be changed:

 React.unmountComponentAtNode(instance.getDOMNode().parent); 

in

 React.unmountComponentAtNode(instance.getDOMNode().parentNode); 

Or, if you go from getDOMNode() to findDOMNode() :

 React.unmountComponentAtNode(React.findDOMNode(instance).parentNode); 
+4
source

All Articles