Matchers for the emitted event on Vue component

Released jest-matcher-vue-test-utils v1.3.0

Added matchers to assert events on the Wrapper object by vue-test-utils.


it("emits special event by click", () => {
const wrapper = shallowMount(Component)
const action = () => wrapper.trigger("click")
expect(action).toEmit(wrapper, "special")
expect(action).toEmit(wrapper, "special", "clicked")

We can assert that the action emits the event (optionally, could check the payload too).


it("emits special event by click", () => {
const wrapper = shallowMount(Component);
expect(wrapper).toHaveEmitted("special", "clicked");

This just asserts emission logs on wrapper.emitted() simply.

I would add similar matcher toHaveEmittedNth to assert not only the single event like the standard matcher toHaveBeenNthCalled by Jest.

Before releasing without “beta” tag, experimented with the actual Vue project on Indiegogo. Thanks, Super Famous Mike and Josh Dhaliwal for giving important feedback to these new matchers ✨


A Japanese duo by a product designer and a software…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store