File tree Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 53
53
"mocha" : " ^2.3.4" ,
54
54
"rollup" : " ^0.25.4" ,
55
55
"rollup-plugin-babel" : " ^2.4.0" ,
56
+ "sinon" : " ^1.17.3" ,
57
+ "sinon-chai" : " ^2.8.0" ,
56
58
"todomvc-app-css" : " ^2.0.3" ,
57
59
"uglify-js" : " ^2.6.2" ,
58
60
"vue" : " ^1.0.17" ,
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ export default function (Vue) {
51
51
if ( actions ) {
52
52
options . methods = options . methods || { }
53
53
for ( let key in actions ) {
54
- options . methods [ key ] = makeBoundAction ( this . $store , actions [ key ] )
54
+ options . methods [ key ] = makeBoundAction ( this . $store , actions [ key ] , key )
55
55
}
56
56
}
57
57
}
@@ -126,9 +126,13 @@ export default function (Vue) {
126
126
*
127
127
* @param {Store } store
128
128
* @param {Function } action
129
+ * @param {String } key
129
130
*/
130
131
131
- function makeBoundAction ( store , action ) {
132
+ function makeBoundAction ( store , action , key ) {
133
+ if ( typeof action !== 'function' ) {
134
+ console . warn ( `[vuex] Action bound to key 'vuex.actions.${ key } ' is not a function.` )
135
+ }
132
136
return function vuexBoundAction ( ...args ) {
133
137
return action . call ( this , store , ...args )
134
138
}
Original file line number Diff line number Diff line change 1
- import { expect } from 'chai'
1
+ import chai , { expect } from 'chai'
2
+ import sinonChai from 'sinon-chai'
3
+ import sinon from 'sinon'
2
4
import Vue from 'vue'
3
5
import Vuex from '../../src'
4
6
import * as util from '../../src/util'
5
7
6
8
Vue . use ( Vuex )
9
+ chai . use ( sinonChai )
7
10
8
11
const TEST = 'TEST'
9
12
@@ -404,4 +407,19 @@ describe('Vuex', () => {
404
407
} )
405
408
expect ( store . state . a ) . to . equal ( 3 )
406
409
} )
410
+
411
+ it ( 'console.warn when action is not a function' , function ( ) {
412
+ sinon . spy ( console , 'warn' )
413
+
414
+ new Vue ( {
415
+ vuex : {
416
+ actions : {
417
+ test : undefined
418
+ }
419
+ }
420
+ } )
421
+
422
+ expect ( console . warn ) . to . have . been . calledWith ( '[vuex] Action bound to key \'vuex.actions.test\' is not a function.' )
423
+ console . warn . restore ( )
424
+ } )
407
425
} )
You can’t perform that action at this time.
0 commit comments