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

38 lines
822 B
JavaScript
Raw Normal View History

2017-08-11 15:58:20 -04: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, payload) => {
const mutation = expectedMutations[count];
try {
2018-03-29 05:33:44 -04:00
expect(mutation.type).toEqual(type);
2017-08-11 15:58:20 -04:00
if (payload) {
2018-03-29 05:33:44 -04:00
expect(mutation.payload).toEqual(payload);
2017-08-11 15:58:20 -04:00
}
} catch (error) {
2018-03-29 04:37:01 -04:00
done.fail(error);
2017-08-11 15:58:20 -04: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 05:33:44 -04:00
expect(count).toEqual(0);
2017-08-11 15:58:20 -04:00
done();
}
};