Skip to content

Instantly share code, notes, and snippets.

@maxpou
Created October 6, 2017 14:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
export const testAction = (action, payload, state, expectedMutations, done) => {
let count = 0
// mock commit
const commit = (type, payload) => {
const mutation = expectedMutations[count]
try {
expect(mutation.type).toEqual(type)
if (payload) {
expect(mutation.payload).toEqual(payload)
}
} catch (error) {
done(error)
}
count++
if (count >= expectedMutations.length) {
done()
}
}
// call the action with mocked store and arguments
action({ commit, state }, payload)
// check if no mutations should have been dispatched
if (expectedMutations.length === 0) {
expect(count).toEqual(0)
done()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment