File tree Expand file tree Collapse file tree 2 files changed +38
-6
lines changed
test/unit/features/instance Expand file tree Collapse file tree 2 files changed +38
-6
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,15 @@ if (process.env.NODE_ENV !== 'production') {
1212 'require' // for Webpack/Browserify
1313 )
1414
15+ const warnNonPresent = ( target , key ) => {
16+ warn (
17+ `Property or method "${ key } " is not defined on the instance but ` +
18+ `referenced during render. Make sure to declare reactive data ` +
19+ `properties in the data option.` ,
20+ target
21+ )
22+ }
23+
1524 hasProxy =
1625 typeof Proxy !== 'undefined' &&
1726 Proxy . toString ( ) . match ( / n a t i v e c o d e / )
@@ -21,14 +30,16 @@ if (process.env.NODE_ENV !== 'production') {
2130 const has = key in target
2231 const isAllowed = allowedGlobals ( key ) || key . charAt ( 0 ) === '_'
2332 if ( ! has && ! isAllowed ) {
24- warn (
25- `Property or method "${ key } " is not defined on the instance but ` +
26- `referenced during render. Make sure to declare reactive data ` +
27- `properties in the data option.` ,
28- target
29- )
33+ warnNonPresent ( target , key )
3034 }
3135 return has || ! isAllowed
36+ } ,
37+
38+ get ( target , key ) {
39+ if ( typeof key === 'string' && ! ( key in target ) ) {
40+ warnNonPresent ( target , key )
41+ }
42+ return target [ key ]
3243 }
3344 }
3445
Original file line number Diff line number Diff line change 1+ import Vue from 'vue'
2+
3+ if ( typeof Proxy !== 'undefined' ) {
4+ describe ( 'render proxy' , ( ) => {
5+ it ( 'should warn missing property in render fns with `with`' , ( ) => {
6+ new Vue ( {
7+ template : `<div>{{ a }}</div>`
8+ } ) . $mount ( )
9+ expect ( `Property or method "a" is not defined` ) . toHaveBeenWarned ( )
10+ } )
11+
12+ it ( 'should warn missing property in render fns without `with`' , ( ) => {
13+ new Vue ( {
14+ render ( h ) {
15+ return h ( 'div' , [ this . a ] )
16+ }
17+ } ) . $mount ( )
18+ expect ( `Property or method "a" is not defined` ) . toHaveBeenWarned ( )
19+ } )
20+ } )
21+ }
You can’t perform that action at this time.
0 commit comments