有没有办法卸载和垃圾收集使用安装的 React 组件TestUtils.renderIntoDocument
在 jsdom 测试中?
我正在尝试测试发生的事情componentWillUnmount
and TestUtils.renderIntoDocument
不返回任何 DOM 节点来调用React. unmountComponentAtNode
on.
不,但您可以简单地使用ReactDOM.render
手动:
var container = document.createElement('div');
ReactDOM.render(<Component />, container);
// ...
ReactDOM.unmountComponentAtNode(container);
这正是ReactTestUtils 到底做了什么 https://github.com/facebook/react/blob/87bcbff/src/test/ReactTestUtils.js#L50-L58,所以如果您需要对容器的引用,没有理由不这样做。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)