0๐
I checked vue-test-utils
docs for โemittedโ:
https://vue-test-utils.vuejs.org/api/wrapper/emitted.html
Can you try to wrap it in vm.$nextTick
:
it("rating component should emit call to parent updateRating function", (done) => {
const wrapper = factory({});
const ratingComp = wrapper.find({ref: "ratings"});
ratingComp.vm.$emit("updateRating", 1);
wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().updateRating).toEqual(1);
expect((wrapper.vm as any).updateRating).toHaveBeenCalled();
done()
})
});
- [Vuejs]-How to check if a user is online in laravel vue.js
- [Vuejs]-Error in render: "TypeError: Cannot read property 'PAY_TYPE' of null"
0๐
I figured it out this is what I used below:
it("rating component should emit call to parent updateRating function", () => {
const wrapper = factory({});
const updateRating = jest.fn();
wrapper.setMethods({ updateRating });
wrapper.find({ ref: "ratings" }).vm.$emit("updateRating", { idx: 9 });
expect(updateRating).toHaveBeenCalled();
expect(updateRating).toHaveBeenCalledWith({ idx: 9 });
});
Thanks for your help with this ๐
Source:stackexchange.com