Skip to content

Commit

Permalink
add test cases for the new before/after action subscribers (vuejs#1098)
Browse files Browse the repository at this point in the history
make sure that the before subscriber is called before the action, while the after subscriber is called after it resolves
  • Loading branch information
Wael Al-Sallami committed Jan 3, 2018
1 parent cdba92e commit 571fad9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/unit/modules.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,37 @@ describe('Modules', () => {
store.state
)
})

it('action before/after subscribers', (done) => {
const beforeSpy = jasmine.createSpy()
const afterSpy = jasmine.createSpy()
const store = new Vuex.Store({
actions: {
[TEST]: () => new Promise(resolve => resolve())
},
plugins: [
store => {
store.subscribeAction({
before: beforeSpy,
after: afterSpy
})
}
]
})
store.dispatch(TEST, 2)
expect(beforeSpy).toHaveBeenCalledWith(
{ type: TEST, payload: 2 },
store.state
)
expect(afterSpy).not.toHaveBeenCalled()
Vue.nextTick(() => {
expect(afterSpy).toHaveBeenCalledWith(
{ type: TEST, payload: 2 },
store.state
)
done()
})
})
})

it('asserts a mutation should be a function', () => {
Expand Down

0 comments on commit 571fad9

Please sign in to comment.