File tree Expand file tree Collapse file tree 2 files changed +37
-6
lines changed Expand file tree Collapse file tree 2 files changed +37
-6
lines changed Original file line number Diff line number Diff line change @@ -74,12 +74,16 @@ export default function (Vue) {
74
74
*/
75
75
76
76
function defineVuexGetter ( vm , key , getter ) {
77
- Object . defineProperty ( vm , key , {
78
- enumerable : true ,
79
- configurable : true ,
80
- get : makeComputedGetter ( vm . $store , getter ) ,
81
- set : setter
82
- } )
77
+ if ( typeof getter !== 'function' ) {
78
+ console . warn ( `[vuex] Getter bound to key 'vuex.getters.${ key } ' is not a function.` )
79
+ } else {
80
+ Object . defineProperty ( vm , key , {
81
+ enumerable : true ,
82
+ configurable : true ,
83
+ get : makeComputedGetter ( vm . $store , getter ) ,
84
+ set : setter
85
+ } )
86
+ }
83
87
}
84
88
85
89
/**
@@ -95,6 +99,7 @@ export default function (Vue) {
95
99
96
100
function makeComputedGetter ( store , getter ) {
97
101
const id = store . _getterCacheId
102
+
98
103
// cached
99
104
if ( getter [ id ] ) {
100
105
return getter [ id ]
Original file line number Diff line number Diff line change @@ -464,4 +464,30 @@ describe('Vuex', () => {
464
464
expect ( console . warn ) . to . have . been . calledWith ( '[vuex] Action bound to key \'vuex.actions.test\' is not a function.' )
465
465
console . warn . restore ( )
466
466
} )
467
+
468
+ it ( 'console.warn when getter is not a function' , function ( ) {
469
+ const store = new Vuex . Store ( {
470
+ state : {
471
+ a : 1
472
+ } ,
473
+ mutations : {
474
+ [ TEST ] ( state , amount ) {
475
+ state . a += amount
476
+ }
477
+ }
478
+ } )
479
+ sinon . spy ( console , 'warn' )
480
+
481
+ new Vue ( {
482
+ store,
483
+ vuex : {
484
+ getters : {
485
+ test : undefined
486
+ }
487
+ }
488
+ } )
489
+
490
+ expect ( console . warn ) . to . have . been . calledWith ( '[vuex] Getter bound to key \'vuex.getters.test\' is not a function.' )
491
+ console . warn . restore ( )
492
+ } )
467
493
} )
You can’t perform that action at this time.
0 commit comments