Commit 91fcb311 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch '49413-test-action-no-return' into 'master'

Allow testAction to work for async actions that don't return a Promise

Closes #49413

See merge request gitlab-org/gitlab-ce!20718
parents daa1ac0f 0bb1009c
......@@ -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;
......
......@@ -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);
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment