gitlab-org--gitlab-foss/spec/javascripts/helpers/vuex_action_helper.js
Filipa Lacerda ee3cf5d6f3
[ci skip] Adds tests to vuex and collapsibe component
Formats dates
Fixes clipboard button
Simplifies HTML
2017-09-20 19:03:53 +01:00

37 lines
825 B
JavaScript

/* 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 {
expect(mutation.type).to.equal(type);
if (payload) {
expect(mutation.payload).to.deep.equal(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).to.equal(0);
done();
}
};