Created
October 6, 2017 14:02
-
-
Save maxpou/aef76bac28a82879bdfe55a5ba0d0bc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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