[Vuejs]-Vue Test utils custom event trigger is not working

0👍

The problem is with the .trigger. As docs says it fires event on the DOM node. If you explicitly specifying the event in emits block it says that your component will fire it. Otherwise VTU just trigger the load-data event as DOM node event.

In your case you shoud use $emit

wrapper.findComponent('[data-test="dropdown-test"]').vm.$emit('load-data')

await wrapper.vm.$nextTick() // Wait until $emits have been handled
// then
expect(wrapper.emitted('first-event'))...
expect(wrapper.emitted('second-event'))...

Leave a comment