I am trying to test a component been called in vue using jest and vue-utils but it is giving the error below
expect(jest.fn()).toHaveBeenCalled()
Expected mock function to have been called, but it was not called.
RandomPhoneNumber component The component makes use of ant-design-vue UI
<div>
<a-button
type="primary"
@click="generatePhone"
size="large"
class="btn-generate"
>Generate Phone Numbers</a-button>
</div>
What I have done is below
it('should call generatePhone', () => {
const wrapper = mount(RandomPhoneNumber, {
localVue,
sync: false
})
const spy = jest.fn()
wrapper.vm.generatePhone = spy
const button = wrapper.find('.btn-generate')
button.trigger('click')
expect(wrapper.vm.generatePhone).toHaveBeenCalled()
})
Can anybody share more light on this and what am I doing wrong here.