allow for testAction to wait until all promises are resolved
This commit is contained in:
parent
66f5be832b
commit
0bb1009ced
|
@ -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);
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue