I am trying to simulate a button click of a quasar QBtn component in Jest(using vue-test-utils). I need to test if the @click method gets called when the button is clicked so I did the following
it("Expects createAccount to be called", async () => {
const button = wrapper.findComponent(QBtn);
await button.trigger('click');
expect(methods.createAccount).toBeCalled();
})
And I also mocked createAccount
function using jest.fn()
But I always get 0 calls of the function, although it works if I directly use
wrapper.vm.createAccount()
And just check if the function got called...
Any ideas how I can trigger the click event on the QBtn? I also tried using find('button')
and triggering click, did not work either