I'm writing test on a vue component that must call a method when focus is lost.
According to vue-test-utils I should use wrapper.trigger('blur'). But the method is not fired.
I suspect that blur isn't the proper event name, since it appears as focusout in the console. But changing the name doesn't solve the problem.
Component:
<template>
<input @blur="foo" />
</template>
...
Test file:
import { mount } from 'vue-test-utils'
import MyComponent from '../MyComponent'
describe('myComponent', () => {
const mockFn = jest.fn()
const wrapper = mount(MyComponent, { mocks: { foo: mockFn } })
it('fires "foo" on blur', () => {
wrapper.trigger('blur')
expect(mockFn).toHaveBeenCalled()
}
I expected that using wrapper.trigger('blur') would fire foo, which is mocked with mockFn. But mockFn is never called.