4
votes

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

1

1 Answers

-1
votes

For those types of tests, I use cypress; personnaly I prefer to use jest to test methods, computed, etc...