Jestjs jest assert函数已被调用两次,两次都使用特定参数
我正在测试一个vue组件,该组件在装载时调度操作(Jestjs jest assert函数已被调用两次,两次都使用特定参数,jestjs,vue-test-utils,Jestjs,Vue Test Utils,我正在测试一个vue组件,该组件在装载时调度操作(functionx)。单击特定的刷新按钮时,会发送相同的操作(functionx)。我正在测试刷新按钮的行为-即使用参数'functionx'调用vuex分派操作。这是我的测试: it('makes an api call to server when refresh button is clicked', () => { store.dispatch = jest.fn(); const wrapper =
functionx
)。单击特定的刷新
按钮时,会发送相同的操作(functionx
)。我正在测试刷新按钮的行为-即使用参数'functionx'调用vuex分派操作。这是我的测试:
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');
})
});
过去了。现在,由于相同的操作在安装组件时被初始调度。所以总调度调用两次。我知道我可以使用.tohaveNerthCalledWith(nthCall,arg1,arg2,…)
来检查是否使用相同的参数调用了dispatch,但为此我必须编写两个expect语句,如下所示:
expect(store.dispatch).toHaveBeenNthCalledWith(1, 'categoryStore/fetchCategories');
expect(store.dispatch).toHaveBeenNthCalledWith(2, 'categoryStore/fetchCategories');
我有没有办法在一句话中实现上述目标?expect
对象上可以使用的任何匹配器函数或任何属性