2017-08-11 19:58:20 +00:00
|
|
|
/* eslint-disable */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* helper for testing action with expected mutations
|
|
|
|
* https://vuex.vuejs.org/en/testing.html
|
|
|
|
*/
|
|
|
|
export default (action, payload, state, expectedMutations, done) => {
|
|
|
|
let count = 0;
|
|
|
|
|
|
|
|
// mock commit
|
2018-03-29 09:43:32 +00:00
|
|
|
const commit = (type, mutationPayload) => {
|
2017-08-11 19:58:20 +00:00
|
|
|
const mutation = expectedMutations[count];
|
|
|
|
|
2018-03-29 09:43:32 +00:00
|
|
|
expect(mutation.type).toEqual(type);
|
|
|
|
|
|
|
|
if (mutation.payload) {
|
|
|
|
expect(mutation.payload).toEqual(mutationPayload);
|
2017-08-11 19:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2018-03-29 09:33:44 +00:00
|
|
|
expect(count).toEqual(0);
|
2017-08-11 19:58:20 +00:00
|
|
|
done();
|
|
|
|
}
|
|
|
|
};
|