How to capture an event in a stub? [Vue-test-utils]

Asked

Viewed 37 times

1

I’m trying to test an event similar to this:

// template: <form @submit.prevent="save"></form>
const save = jest.fn()
const wrapper = mount(MyComponent, {methods: { save }})
wrapper.find('form').trigger('submit.prevent')
expect(save).toBeCalled() // Sucesso

This event invokes a method in the component and it works very well.

But if I use a custom component, the method is not called

// template: <my-custom-form @submit="save"></my-custom-form>
const save = jest.fn()
const wrapper = mount(MyComponent, {methods: { save }, stubs: ['my-custom-form']})
wrapper.find('my-custom-form-stub').trigger('submit')
expect(save).toBeCalled() // Expected mock function to have been called, but it was not called.

How to solve this?

1 answer

1

That way you solved the problem

<my-custom-form @submit.native.prevent="save"></my-custom-form>

Reference link

Browser other questions tagged

You are not signed in. Login or sign up in order to post.