我正在尝试测试一个呈现索环 Menu
组件的组件。grommetMenu
组件将一个绝对定位的菜单呈现到文档的顶层,作为子级插入到body
. 因此,它呈现在包装器的范围之外。我可以通过document.body.innerHTML
(参考 jsdom 文档)找到它,但我想使用酶与它进行交互。有什么建议吗?
我的测试:
const wrapper = mount(
<MyComponent checkThis={checkThisSpy} />
);
wrapper.find('.spec-menu').simulate('click');
console.log(document.body.innerHTML); // Shows the absolute menu inserted into the body
执行此操作的索环中的线document.body.insertBefore(drop.container, document.body.firstChild);
。https://github.com/grommet/grommet/blob/master/src/js/utils/Drop.js#L197
只是在寻找有关处理此问题的最佳方法的一些指导。谢谢!