提交 91fcb311 编写于 作者: F 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
......@@ -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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册