Skip to content

Commit 571fad9

Browse files
author
Wael Al-Sallami
committed
add test cases for the new before/after action subscribers (vuejs#1098)
make sure that the before subscriber is called before the action, while the after subscriber is called after it resolves
1 parent cdba92e commit 571fad9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/unit/modules.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,37 @@ describe('Modules', () => {
668668
store.state
669669
)
670670
})
671+
672+
it('action before/after subscribers', (done) => {
673+
const beforeSpy = jasmine.createSpy()
674+
const afterSpy = jasmine.createSpy()
675+
const store = new Vuex.Store({
676+
actions: {
677+
[TEST]: () => new Promise(resolve => resolve())
678+
},
679+
plugins: [
680+
store => {
681+
store.subscribeAction({
682+
before: beforeSpy,
683+
after: afterSpy
684+
})
685+
}
686+
]
687+
})
688+
store.dispatch(TEST, 2)
689+
expect(beforeSpy).toHaveBeenCalledWith(
690+
{ type: TEST, payload: 2 },
691+
store.state
692+
)
693+
expect(afterSpy).not.toHaveBeenCalled()
694+
Vue.nextTick(() => {
695+
expect(afterSpy).toHaveBeenCalledWith(
696+
{ type: TEST, payload: 2 },
697+
store.state
698+
)
699+
done()
700+
})
701+
})
671702
})
672703

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

0 commit comments

Comments
 (0)