I am doing some tests and I want to check if a method is called after I trigger a click in an element, but the test keeps saying that is wasn't called and I don't know why
Here is my test:
test('some test', () => {
        const somethingChanged= jest.spyOn(Component.methods, 'somethingChanged')
        const wrapper = mount(Component, {
            propsData: data
        })
        const element= wrapper.find('.c-element').trigger('click')
        expect(somethingChanged).toBeCalled()
    })
This keeps saying that the number of calls is 0 and I don't know what I'm doing wrong This method is triggered in the component so I know it works
As trigger documentation states,
Triggers an event asynchronously on the Wrapper DOM node.
It should be:
const element= wrapper.find('.c-element').trigger('click')
await wrapper.vm.$nextTick()
expect(somethingChanged).toBeCalled()
The use of await assumes that test function should be async.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With