diff options
| author | Lukas Eipert <leipert@gitlab.com> | 2018-07-09 18:27:09 +0200 |
|---|---|---|
| committer | Lukas Eipert <leipert@gitlab.com> | 2018-07-11 20:20:32 +0200 |
| commit | 89368e512f4bd63bc01a135029f28df9be4f9388 (patch) | |
| tree | e9f06141bca6d8bc04af64b0dd0a0e596f85486f | |
| parent | c74e57bb99cd2e6c292e62c313546fb3afc6a881 (diff) | |
| download | gitlab-ce-89368e512f4bd63bc01a135029f28df9be4f9388.tar.gz | |
Allow for action to be a promise
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/44912
| -rw-r--r-- | spec/javascripts/helpers/vuex_action_helper.js | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/spec/javascripts/helpers/vuex_action_helper.js b/spec/javascripts/helpers/vuex_action_helper.js index d6ab0aeeed7..4f5ec721aab 100644 --- a/spec/javascripts/helpers/vuex_action_helper.js +++ b/spec/javascripts/helpers/vuex_action_helper.js @@ -33,9 +33,6 @@ export default (action, payload, state, expectedMutations, expectedActions, done } mutationsCount += 1; - if (mutationsCount >= expectedMutations.length) { - done(); - } }; // mock dispatch @@ -49,23 +46,29 @@ export default (action, payload, state, expectedMutations, expectedActions, done } actionsCount += 1; - if (actionsCount >= expectedActions.length) { - done(); - } }; - // call the action with mocked store and arguments - action({ commit, state, dispatch, rootState: state }, payload); + return new Promise((resolve, reject) => { + try { + const result = action({ commit, state, dispatch, rootState: state }, payload); + resolve(result); + } catch (e) { + reject(e); + } - // check if no mutations should have been dispatched - if (expectedMutations.length === 0) { - expect(mutationsCount).toEqual(0); - done(); - } + }).then(() => { + // check if no mutations should have been dispatched + if (expectedMutations.length === 0) { + expect(mutationsCount).toEqual(0); + } + + // check if no mutations should have been dispatched + if (expectedActions.length === 0) { + expect(actionsCount).toEqual(0); + } - // check if no mutations should have been dispatched - if (expectedActions.length === 0) { - expect(actionsCount).toEqual(0); done(); - } + + }); + }; |
