我试图对一个“mouseover”和“mouseleave”事件进行单元测试,该事件显示的是一个v卡操作,具体取决于鼠标操作。我在我的vuejs2 webpack应用程序中使用vue-test-utils .以下是我在网上发现的:鼠标点击示例。提前感谢任何帮助的人
下面是我的代码--实际的html模板代码:
<v-card class="menuCard pa-1 elevation-2 f-basis-0 my-2"
@mouseover="isBlockAct = true" @mouseleave="isBlockAct = (!checked?
false:true)">
<v-checkbox v-model="checked" id="checkbox" class="diCheckbox ma-0" hide-
details></v-checkbox>
<v-card-actions class="myUpHere pa-0">
<v-layout row :class="{'isAct': isBlockAct, 'isNotAct': !isBlockAct}">
</v-card>下面是我在我的spec.js代码中尝试过的:
describe("Over event", () => {
it("shows the icons if the card is over or not", () => {
const wrapper = mount(MenuRepasRecetteCard, {
propsData: {}
});
wrapper.find(".menuCard").trigger("mouseover");
expect(wrapper.find(".isAct").text()).contain("remove_red_eye");
});发布于 2018-06-20 13:32:57
你需要等待事件被vue处理。
describe("Over event", (done) => {
it("shows the icons if the card is over or not", () => {
const wrapper = mount(MenuRepasRecetteCard, {
propsData: {}
});
wrapper.find(".menuCard").trigger("mouseover");
wrapper.vm.$nextTick( () => {
expect(wrapper.find(".isAct").text()).contain("remove_red_eye");
done();
});
});
});发布于 2021-07-05 19:01:54
await关键字可用于等待触发器完成:
await wrapper.find(".menuCard").trigger("mouseover");async还需要添加到闭包中:
it("shows the icons if the card is over or not", async () => {发布于 2019-04-16 08:28:27
不幸的是,我不能对拉斯的回答发表评论。医生说不需要nextTick。
Vue Test Utils同步触发事件。因此,不需要Vue.nextTick。
-Source:https://vue-test-utils.vuejs.org/guides/dom-events.html#important
https://stackoverflow.com/questions/50410059
复制相似问题