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 5353 "mocha" : " ^2.3.4" ,
5454 "rollup" : " ^0.25.4" ,
5555 "rollup-plugin-babel" : " ^2.4.0" ,
56+ "sinon" : " ^1.17.3" ,
57+ "sinon-chai" : " ^2.8.0" ,
5658 "todomvc-app-css" : " ^2.0.3" ,
5759 "uglify-js" : " ^2.6.2" ,
5860 "vue" : " ^1.0.17" ,
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ export default function (Vue) {
5151 if ( actions ) {
5252 options . methods = options . methods || { }
5353 for ( let key in actions ) {
54- options . methods [ key ] = makeBoundAction ( this . $store , actions [ key ] )
54+ options . methods [ key ] = makeBoundAction ( this . $store , actions [ key ] , key )
5555 }
5656 }
5757 }
@@ -126,9 +126,13 @@ export default function (Vue) {
126126 *
127127 * @param {Store } store
128128 * @param {Function } action
129+ * @param {String } key
129130 */
130131
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+ }
132136 return function vuexBoundAction ( ...args ) {
133137 return action . call ( this , store , ...args )
134138 }
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'
24import Vue from 'vue'
35import Vuex from '../../src'
46import * as util from '../../src/util'
57
68Vue . use ( Vuex )
9+ chai . use ( sinonChai )
710
811const TEST = 'TEST'
912
@@ -404,4 +407,19 @@ describe('Vuex', () => {
404407 } )
405408 expect ( store . state . a ) . to . equal ( 3 )
406409 } )
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+ } )
407425} )
You can’t perform that action at this time.
0 commit comments