Skip to content
代码片段 群组 项目
未验证 提交 0bb1009c 编辑于 作者: Lukas Eipert's avatar Lukas Eipert
浏览文件

allow for testAction to wait until all promises are resolved

上级 66f5be83
No related branches found
No related tags found
无相关合并请求
...@@ -84,14 +84,12 @@ export default ( ...@@ -84,14 +84,12 @@ export default (
done(); done();
}; };
return new Promise((resolve, reject) => { const result = action({ commit, state, dispatch, rootState: state }, payload);
try {
const result = action({ commit, state, dispatch, rootState: state }, payload); return new Promise(resolve => {
resolve(result); setImmediate(resolve);
} catch (e) {
reject(e);
}
}) })
.then(() => result)
.catch(error => { .catch(error => {
validateResults(); validateResults();
throw error; throw error;
......
...@@ -138,4 +138,29 @@ describe('VueX test helper (testAction)', () => { ...@@ -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);
});
}); });
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册