summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2018-03-28 21:11:48 +0100
committerFilipa Lacerda <filipa@gitlab.com>2018-03-28 21:11:48 +0100
commit7baa24e2b9abc0137d17fe24ae2bce3f7800a890 (patch)
tree09a4a5a34a1ffbc6b991515d30eab41b3d91a60d
parentdb555cb7cd5390381bf517c3b73b2aa0a27e5375 (diff)
downloadgitlab-ce-fe-actions-vuex-helper.tar.gz
Mock dispatch function in vuex action helperfe-actions-vuex-helper
-rw-r--r--spec/javascripts/helpers/vuex_action_helper.js23
1 files changed, 22 insertions, 1 deletions
diff --git a/spec/javascripts/helpers/vuex_action_helper.js b/spec/javascripts/helpers/vuex_action_helper.js
index 2d386fe1da5..8ba57956e47 100644
--- a/spec/javascripts/helpers/vuex_action_helper.js
+++ b/spec/javascripts/helpers/vuex_action_helper.js
@@ -26,8 +26,29 @@ export default (action, payload, state, expectedMutations, done) => {
}
};
+ // mock dispatch
+ const dispatch = (type, dispatchPayload) => {
+ const mutation = expectedMutations[count];
+
+ try {
+ expect(mutation.type).to.equal(type);
+
+ if (dispatchPayload) {
+ expect(mutation.payload).to.deep.equal(dispatchPayload);
+ }
+ } catch (error) {
+ done(error);
+ }
+
+ count++;
+
+ if (count >= expectedMutations.length) {
+ done();
+ }
+ };
+
// call the action with mocked store and arguments
- action({ commit, state }, payload);
+ action({ commit, state, dispatch }, payload);
// check if no mutations should have been dispatched
if (expectedMutations.length === 0) {