有没有办法卸载和垃圾收集使用 TestUtils.renderIntoDocument
安装的 React 组件在 jsdom 测试中?
我正在尝试测试 componentWillUnmount
上发生的事情和TestUtils.renderIntoDocument
不返回任何 DOM 节点来调用 React. unmountComponentAtNode
上。
最佳答案
不,但您可以简单地手动使用 ReactDOM.render
:
var container = document.createElement('div');
ReactDOM.render(<Component />, container);
// ...
ReactDOM.unmountComponentAtNode(container);
这正是what ReactTestUtils does anyway ,因此如果您需要对容器的引用,没有理由不这样做。
关于javascript - 在 jsdom 测试中卸载/销毁组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23973942/