Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing mouseover event in vue-test-utils

I am trying to make unit test for a @mouseover and @mouseleave event who's displaying a v-card-actions depending from the mouseover. I am using vue-test-utils in my vuejs2 webpack application. Here is what i found on the web : vue-utlis mouse click exemple . Thanks in advance to anyone who's helping

Here is my code actual html template code:

  <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>

Here is what i tried in my spec.js code:

  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");
    });
like image 847
Emile Cantero Avatar asked Dec 23 '22 07:12

Emile Cantero


2 Answers

u need to wait for the event to be processed by 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();
        });
    });
});
like image 90
Lars Avatar answered Jan 04 '23 23:01

Lars


The await keyword can be used to wait for the trigger to complete:

await wrapper.find(".menuCard").trigger("mouseover");

async would also need adding to the closure:

it("shows the icons if the card is over or not", async () => {
like image 45
Simon Dean Avatar answered Jan 04 '23 23:01

Simon Dean