File tree 2 files changed +37
-8
lines changed
test/unit/specs/directives
2 files changed +37
-8
lines changed Original file line number Diff line number Diff line change 1
1
var _ = require ( '../util' )
2
2
3
- module . exports = {
3
+ module . exports = {
4
+
5
+ acceptStatement : true ,
4
6
5
7
bind : function ( ) {
6
8
var child = this . el . __vue__
@@ -11,14 +13,21 @@ module.exports = {
11
13
)
12
14
return
13
15
}
14
- var method = this . vm [ this . expression ]
15
- if ( ! method ) {
16
+ } ,
17
+
18
+ update : function ( handler , oldHandler ) {
19
+ if ( typeof handler !== 'function' ) {
16
20
_ . warn (
17
- '` v-events` cannot find method " ' + this . expression +
18
- '" on the parent instance .'
21
+ 'Directive " v-events: ' + this . expression + '" ' +
22
+ 'expects a function value .'
19
23
)
24
+ return
25
+ }
26
+ var child = this . el . __vue__
27
+ if ( oldHandler ) {
28
+ child . $off ( this . arg , oldHandler )
20
29
}
21
- child . $on ( this . arg , method )
30
+ child . $on ( this . arg , handler )
22
31
}
23
32
24
33
// when child is destroyed, all events are turned off,
Original file line number Diff line number Diff line change @@ -59,9 +59,10 @@ if (_.inBrowser) {
59
59
expect ( spy ) . not . toHaveBeenCalled ( )
60
60
} )
61
61
62
- it ( 'should warn when method not found on parent ' , function ( ) {
63
- new Vue ( {
62
+ it ( 'should warn on non-function values ' , function ( ) {
63
+ var vm = new Vue ( {
64
64
el : el ,
65
+ data : { test : 123 } ,
65
66
template : '<div v-component="test" v-events="test:test"></div>' ,
66
67
components : {
67
68
test : { }
@@ -70,5 +71,24 @@ if (_.inBrowser) {
70
71
expect ( _ . warn ) . toHaveBeenCalled ( )
71
72
} )
72
73
74
+ it ( 'should accept inline statement' , function ( done ) {
75
+ var vm = new Vue ( {
76
+ el : el ,
77
+ data : { a :1 } ,
78
+ template : '<div v-component="test" v-events="test:a++"></div>' ,
79
+ components : {
80
+ test : {
81
+ compiled : function ( ) {
82
+ this . $emit ( 'test' )
83
+ }
84
+ }
85
+ }
86
+ } )
87
+ _ . nextTick ( function ( ) {
88
+ expect ( vm . a ) . toBe ( 2 )
89
+ done ( )
90
+ } )
91
+ } )
92
+
73
93
} )
74
94
}
You can’t perform that action at this time.
0 commit comments