@@ -37,6 +37,25 @@ describe('Store', () => {
37
37
expect ( store . state . a ) . toBe ( 3 )
38
38
} )
39
39
40
+ it ( 'asserts committed type' , ( ) => {
41
+ const store = new Vuex . Store ( {
42
+ state : {
43
+ a : 1
44
+ } ,
45
+ mutations : {
46
+ // Maybe registered with undefined type accidentally
47
+ // if the user has typo in a constant type
48
+ undefined ( state , n ) {
49
+ state . a += n
50
+ }
51
+ }
52
+ } )
53
+ expect ( ( ) => {
54
+ store . commit ( undefined , 2 )
55
+ } ) . toThrowError ( / E x p e c t s s t r i n g a s t h e t y p e , b u t f o u n d u n d e f i n e d / )
56
+ expect ( store . state . a ) . toBe ( 1 )
57
+ } )
58
+
40
59
it ( 'dispatching actions, sync' , ( ) => {
41
60
const store = new Vuex . Store ( {
42
61
state : {
@@ -166,6 +185,30 @@ describe('Store', () => {
166
185
} )
167
186
} )
168
187
188
+ it ( 'asserts dispatched type' , ( ) => {
189
+ const store = new Vuex . Store ( {
190
+ state : {
191
+ a : 1
192
+ } ,
193
+ mutations : {
194
+ [ TEST ] ( state , n ) {
195
+ state . a += n
196
+ }
197
+ } ,
198
+ actions : {
199
+ // Maybe registered with undefined type accidentally
200
+ // if the user has typo in a constant type
201
+ undefined ( { commit } , n ) {
202
+ commit ( TEST , n )
203
+ }
204
+ }
205
+ } )
206
+ expect ( ( ) => {
207
+ store . dispatch ( undefined , 2 )
208
+ } ) . toThrowError ( / E x p e c t s s t r i n g a s t h e t y p e , b u t f o u n d u n d e f i n e d / )
209
+ expect ( store . state . a ) . toBe ( 1 )
210
+ } )
211
+
169
212
it ( 'getters' , ( ) => {
170
213
const store = new Vuex . Store ( {
171
214
state : {
0 commit comments