I am testing a Vue component that dispatches an action(functionx) on mount. The same action(functionx) is dispatched when a particular refresh button is clicked. I am testing the behavior of that refresh button - that is the vuex dispatch action is called with argument 'functionx'. Here is my test:
it('makes an api call to server when refresh button is clicked', () => {
store.dispatch = jest.fn();
const wrapper = mount(Categories, {
sync: false,
store,
localVue
});
const refreshButton = wrapper.find('span.fa-sync');
refreshButton.trigger('click');
expect(store.dispatch).toHaveBeenCalledWith('categoryStore/fetchCategories');
})
});
which passes. Now since the same action is dispatched initially when the component is mounted. So in total dispatch is called twice. I know I can use .toHaveBeenNthCalledWith(nthCall, arg1, arg2, ....) to check that dispatch was called both times with same argument, but for that I will have to write two expect statements, like below:
expect(store.dispatch).toHaveBeenNthCalledWith(1, 'categoryStore/fetchCategories');
expect(store.dispatch).toHaveBeenNthCalledWith(2, 'categoryStore/fetchCategories');
Is there any way I can achieve the above thing in one statement? Any matcher function or any property on the expect object that can be used?