我要测试是否存在某些项目,然后按一下按钮使它们不存在。由于有些元素具有任何指示,并且我必须等待几毫秒才能出现,因此我必须使用一些等待,并且还必须使用事件侦听器来触发事件。我在正确运行此测试时遇到了麻烦,我不明白如何在不被过度指定的情况下将异步与完成结合起来。我正在做类似的事情:
it.only('should remove the markers after the delete icon is clicked', async () => {
await testing.wait.untilCondition(() => view.swQuerySelector('#deleteButton'), undefined, 1000);
const deleteButton = view.swQuerySelector('#deleteButton');
view.addEventListener('event-fired', (done) => {
deleteButton.click()
expect(some.things).to.not.exist;;
done();
},
{once: true}
);
expect(some.things).to.exist;
doSomething(); //this will cause 'event-fired' to fire
});
问题是我必须使root调用异步,以便我可以等待按钮存在。
如果我这样运行,则会收到错误Error: done is not a function
。
如果我尝试将done
传递给异步函数,则会收到一个错误,提示我的函数指定过多。
如果我未在事件监听器的末尾调用done();
,则该函数将超时。
设置这种测试的正确方法是什么?