Skip to content

Instantly share code, notes, and snippets.

@maxpou
Created October 6, 2017 14:02
Show Gist options
  • Save maxpou/aef76bac28a82879bdfe55a5ba0d0bc5 to your computer and use it in GitHub Desktop.
Save maxpou/aef76bac28a82879bdfe55a5ba0d0bc5 to your computer and use it in GitHub Desktop.
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