有没有一种方法可以卸载和垃圾回收TestUtils.renderIntoDocument在jsdom测试中使用过的React组件?
TestUtils.renderIntoDocument
我正在尝试测试发生的事情,componentWillUnmount并且TestUtils.renderIntoDocument不会返回任何要调用的DOM节点React. unmountComponentAtNode。
componentWillUnmount
React. unmountComponentAtNode
不,但是您可以简单地ReactDOM.render手动使用:
ReactDOM.render
var container = document.createElement('div'); ReactDOM.render(<Component />, container); // ... ReactDOM.unmountComponentAtNode(container);
无论如何,这正是ReactTestUtils所做的,因此,如果您需要对容器的引用,则没有理由不这样做。