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();
|
|
|
|
}
|
|
|
|
};
|