如何将 CustomEvent 分派(dispatch)到 StencilJS E2E 测试中的元素:
const page = await newE2EPage({html: `<my-component></my-component>`});
let component = await page.find('my-component');
?? component.dispatch(new Event('my-event'));
在上面的代码中,我尝试将 customEvent 分派(dispatch)到我的组件,以便我可以测试它是否正确响应。但我在 newE2EPage 中没有看到任何方法可以做到这一点。有什么建议吗?
最佳答案
Stenciljs在其E2EElement class上提供了一个triggerEvent函数.
你可以这样做:
const page = await newE2EPage();
await page.setContent('some-markup-with-your-component');
const el = page.find('#element-that-would-emit');
el.triggerEvent('some-custom-event');
await page.waitForChanges();
//Your expect assertion here.
关于typescript - StencilJS E2E测试: How do you dispatch a custom event?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57421937/