File tree Expand file tree Collapse file tree 2 files changed +37
-8
lines changed
test/unit/specs/directives Expand file tree Collapse file tree 2 files changed +37
-8
lines changed Original file line number Diff line number Diff line change 11var _ = require ( '../util' )
22
3- module . exports = {
3+ module . exports = {
4+
5+ acceptStatement : true ,
46
57 bind : function ( ) {
68 var child = this . el . __vue__
@@ -11,14 +13,21 @@ module.exports = {
1113 )
1214 return
1315 }
14- var method = this . vm [ this . expression ]
15- if ( ! method ) {
16+ } ,
17+
18+ update : function ( handler , oldHandler ) {
19+ if ( typeof handler !== 'function' ) {
1620 _ . 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 .'
1923 )
24+ return
25+ }
26+ var child = this . el . __vue__
27+ if ( oldHandler ) {
28+ child . $off ( this . arg , oldHandler )
2029 }
21- child . $on ( this . arg , method )
30+ child . $on ( this . arg , handler )
2231 }
2332
2433 // 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) {
5959 expect ( spy ) . not . toHaveBeenCalled ( )
6060 } )
6161
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 ( {
6464 el : el ,
65+ data : { test : 123 } ,
6566 template : '<div v-component="test" v-events="test:test"></div>' ,
6667 components : {
6768 test : { }
@@ -70,5 +71,24 @@ if (_.inBrowser) {
7071 expect ( _ . warn ) . toHaveBeenCalled ( )
7172 } )
7273
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+
7393 } )
7494}
You can’t perform that action at this time.
0 commit comments