diff options
author | Lukas Eipert <leipert@gitlab.com> | 2018-07-19 16:26:29 +0200 |
---|---|---|
committer | Lukas Eipert <leipert@gitlab.com> | 2018-07-19 16:26:29 +0200 |
commit | 0bb1009ced07bf58776d73992413af2c5cc4665f (patch) | |
tree | d177504fc66e5daf09613eb33409537e4a3c8f77 | |
parent | 66f5be832b40355bda2a56af31c112bfddedb7b1 (diff) | |
download | gitlab-ce-0bb1009ced07bf58776d73992413af2c5cc4665f.tar.gz |
allow for testAction to wait until all promises are resolved
-rw-r--r-- | spec/javascripts/helpers/vuex_action_helper.js | 12 | ||||
-rw-r--r-- | spec/javascripts/helpers/vuex_action_helper_spec.js | 25 |
2 files changed, 30 insertions, 7 deletions
diff --git a/spec/javascripts/helpers/vuex_action_helper.js b/spec/javascripts/helpers/vuex_action_helper.js index 4ca7015184e..dd9174194a1 100644 --- a/spec/javascripts/helpers/vuex_action_helper.js +++ b/spec/javascripts/helpers/vuex_action_helper.js @@ -84,14 +84,12 @@ export default ( done(); }; - return new Promise((resolve, reject) => { - try { - const result = action({ commit, state, dispatch, rootState: state }, payload); - resolve(result); - } catch (e) { - reject(e); - } + const result = action({ commit, state, dispatch, rootState: state }, payload); + + return new Promise(resolve => { + setImmediate(resolve); }) + .then(() => result) .catch(error => { validateResults(); throw error; diff --git a/spec/javascripts/helpers/vuex_action_helper_spec.js b/spec/javascripts/helpers/vuex_action_helper_spec.js index 8d6ad6750c0..09f0bd395c3 100644 --- a/spec/javascripts/helpers/vuex_action_helper_spec.js +++ b/spec/javascripts/helpers/vuex_action_helper_spec.js @@ -138,4 +138,29 @@ describe('VueX test helper (testAction)', () => { }); }); }); + + it('should work with async actions not returning promises', done => { + const data = { FOO: 'BAR' }; + + const promiseAction = ({ commit, dispatch }) => { + dispatch('ACTION'); + + axios + .get(TEST_HOST) + .then(() => { + commit('SUCCESS'); + return data; + }) + .catch(error => { + commit('ERROR'); + throw error; + }); + }; + + mock.onGet(TEST_HOST).replyOnce(200, 42); + + assertion = { mutations: [{ type: 'SUCCESS' }], actions: [{ type: 'ACTION' }] }; + + testAction(promiseAction, null, {}, assertion.mutations, assertion.actions, done); + }); }); |