currently when using the recommended process for testing vuex actions within a component (as detailed here), toHaveBeenCalledWith requires a first argument that contains
{
dispatch: [Function (anonymous)],
commit: [Function (anonymous)],
getters: [Object],
state: [Object],
rootGetters: [Object],
rootState: [Object]
},
a feature that automatically injects this, or provides an easy way to add this into an toHaveBeenCalledWith would be helpful
//component
this.actionName(argument)
//expect
expect(actions.actionName).toHaveBeenCalledWith(argument)
// instead of
expect(actions.actionName).toHaveBeenCalledWith(giantArgumentIncludingContextGettersAndState, argument)
Hi! Not sure if there's a better approach, but currently when I test action in isolation I rely on expect.any(Object) for the first argument:
expect(actions.actionName).toHaveBeenCalledWith(
expect.any(Object), // The Vuex context
{ id: 1, name: 'foo' }
)
I'm gonna close this up, feel free to reopen or fill in a new issue is the suggested solution does not cover your needs 馃
@afontcu yeah this works, may be worth adding to the documentation on that page I linked above so future developers don't run into the same problem.
That's a good idea! Fancy to open up a PR for docs? 馃槈 @An-AngryBear
Most helpful comment
Hi! Not sure if there's a better approach, but currently when I test action in isolation I rely on
expect.any(Object)for the first argument: