Closed
Description
Version
1.0.0-beta.16
Reproduction link
https://github.com/lchanmann/vue-test-utils-setMethods-issue
Steps to reproduce
Clone the repo, then run:
yarn install
yarn test
What is expected?
Should pass tests
What is actually happening?
Test fails
FAIL ./setMethods.test.js
● Console
console.log setMethods.test.js:9
clickMethod
● setMethods › calls stub when event is triggered
expect(jest.fn()).toHaveBeenCalled()
Expected mock function to have been called.
at Object.<anonymous> (setMethods.test.js:17:29)
at new Promise (<anonymous>)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
setMethods.test.js
import { mount } from '@vue/test-utils'
describe('setMethods', () => {
it('calls stub when event is triggered', () => {
const TestComponent = {
template: '<button @click="clickMethod">Click here</button>',
methods: {
clickMethod() {
console.log('clickMethod')
}
}
}
const wrapper = mount(TestComponent)
const clickMethodStub = jest.fn()
wrapper.setMethods({ clickMethod: clickMethodStub })
wrapper.find('button').trigger('click')
expect(clickMethodStub).toHaveBeenCalled()
})
})