[Vuejs]-How to test void function in vue js using jest?

0👍

This implementation spying on the method works for me:

test('fetchItem is called properly',  async () => {

  let wrapper = shallowMount(YourComponent)

  const spy = jest.spyOn(wrapper.vm, 'fetchItem')
    .mockImplementation(() => {
      expect(spy).toHaveBeenCalledWith()
  })
})

Leave a comment