Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from gradecam/feature/actions-should-return
#36 Actions should return the value through vuex
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Vuex from 'vuex' | ||
import Vue from 'vue' | ||
Vue.use(Vuex) | ||
import { Action, Module, MutationAction, VuexModule } from '..' | ||
import { expect } from 'chai' | ||
|
||
@Module | ||
class MyModule extends VuexModule { | ||
foo = '' | ||
|
||
@Action | ||
public value() { | ||
return 'Test1' | ||
} | ||
|
||
@Action | ||
public promise() { | ||
return Promise.resolve('Test2') | ||
} | ||
|
||
@MutationAction({ mutate: ['foo'], rawError: true }) | ||
public promise2(payload: string) { | ||
return Promise.resolve({ foo: payload }) | ||
} | ||
} | ||
|
||
const store = new Vuex.Store({ | ||
modules: { | ||
mm: MyModule | ||
} | ||
}) | ||
|
||
describe('actions return inner promises', () => { | ||
it('should return resolved value', async function() { | ||
const value = await store.dispatch('value') | ||
expect(value).to.equal('Test1') | ||
}) | ||
|
||
it('should return resolved promise', async function() { | ||
const value = await store.dispatch('promise') | ||
expect(value).to.equal('Test2') | ||
}) | ||
|
||
it('should not return resolved promise on a MutationAction', async function() { | ||
// Purposefully not returning value from the action on a MutationAction because it is | ||
// designed to mutate the state and you should access the value off the state | ||
const { | ||
state: { mm } | ||
} = store | ||
let value = 'Test3' | ||
const resp = await store.dispatch('promise2', value) | ||
expect(resp).to.equal(void 0) | ||
expect(mm.foo).to.equal(value) | ||
}) | ||
}) |
108e7ec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@championswimmer could we get a new release on npm that includes this?
Thanks