File tree 2 files changed +38
-6
lines changed
test/unit/features/instance
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') {
12
12
'require' // for Webpack/Browserify
13
13
)
14
14
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
+
15
24
hasProxy =
16
25
typeof Proxy !== 'undefined' &&
17
26
Proxy . toString ( ) . match ( / n a t i v e c o d e / )
@@ -21,14 +30,16 @@ if (process.env.NODE_ENV !== 'production') {
21
30
const has = key in target
22
31
const isAllowed = allowedGlobals ( key ) || key . charAt ( 0 ) === '_'
23
32
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 )
30
34
}
31
35
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 ]
32
43
}
33
44
}
34
45
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