gitlab-org--gitlab-foss/spec/javascripts/helpers/vuex_action_helper.js

35 lines
778 B
JavaScript
Raw Normal View History

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
const commit = (type, mutationPayload) => {
2017-08-11 19:58:20 +00:00
const mutation = expectedMutations[count];
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();
}
};