Is there a way to unmount and garbage collect a React Component that was mounted using TestUtils.renderIntoDocument
inside a jsdom test?
I'm trying to test something that happens on componentWillUnmount
and TestUtils.renderIntoDocument
doesn't return any DOM node to call React. unmountComponentAtNode
on.
No, but you can simply use ReactDOM.render
manually:
var container = document.createElement('div');
ReactDOM.render(<Component />, container);
// ...
ReactDOM.unmountComponentAtNode(container);
This is exactly what ReactTestUtils does anyway, so there's no reason not to do it this way if you need a reference to the container.