diff --git a/src/store/store.ts b/src/store/store.ts index dcd58849..c5ba3f50 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -99,12 +99,7 @@ export class Store extends EventBus { }, ...payload ); - if (result instanceof Promise) { - return new Promise((resolve, reject) => { - result.then(() => resolve()); - result.catch(reject); - }); - } + return result; } commit(type: string, ...payload: any): any { diff --git a/tests/store/store.test.ts b/tests/store/store.test.ts index 128de616..28f125f2 100644 --- a/tests/store/store.test.ts +++ b/tests/store/store.test.ts @@ -160,6 +160,36 @@ describe("basic use", () => { expect(store.state.n).toBe(13); }); + test("return data from dispatching an action", async () => { + const state = { n: 1 }; + const mutations = { + inc({ state }, delta) { + state.n += delta; + }, + setN({ state }, n) { + state.n = n; + } + }; + const actions = { + async dosomething({ commit, dispatch }) { + const val = await dispatch("setTo10"); + commit("inc", val); + }, + async setTo10({ commit }) { + await Promise.resolve(); + commit("setN", 10); + return 5; + } + }; + const store = new Store({ state, mutations, actions }); + + expect(store.state.n).toBe(1); + store.dispatch("dosomething"); + expect(store.state.n).toBe(1); + await nextTick(); + expect(store.state.n).toBe(15); + }); + test("env is given to actions", () => { expect.assertions(1); const someEnv = {};