lmiller1990 / vue-testing-handbook

A guide on testing Vue components and applications
https://lmiller1990.github.io/vue-testing-handbook/
876 stars 160 forks source link

testing an Emitted Events #198

Closed ehsan-shv closed 2 years ago

ehsan-shv commented 2 years ago

In a situation that we want to test just emitting event to parent, what can we do? For example, we have an event emitter like this: emit('onInputButtonClick'); and this event emitter just emits an event to the parent without sending any data.

lmiller1990 commented 2 years ago

Assert that emitted() contains the expected property, in this case expect(wrapper.emitted().onInputButtonClick).toHaveLength(1).