我有一个简单的混合:
export const mixin = superclass => class extends superclass {
firstUpdated() {
super.firstUpdated();
this.dispatchEvent(new CustomEvent('my-event', {
bubbles: true,
composed: true,
detail: {
myEventTriggered: true,
},
}));
}
};
我想测试是否my-event
被解雇。这是我的测试:
it('dispatches the custom event', async () => {
const tag = class extends mixin(LitElement) {};
const el = await fixture(`<${tag}></${tag}>`);
setTimeout(() => el.firstUpdated());
const { detail } = await oneEvent(el, 'my-event');
expect(detail.myEventTriggered).to.be.true;
});
这按预期工作,但我不确定这setTimeout(() => el.firstUpdated());
条线。不应该firstUpdated
在之后调用await fixture
吗?我只是在关注open-wc 的测试指南。