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

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 this 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?

    
asked by anonymous 23.11.2018 / 14:32

1 answer

1

That way you solved the problem

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

Referral link

    
23.11.2018 / 14:56