@@ -29,6 +29,12 @@ if (_.inBrowser) {
2929 } ,
3030 $interpolate : function ( value ) {
3131 return data [ value ]
32+ } ,
33+ $parent : {
34+ _directives : [ ] ,
35+ $get : function ( v ) {
36+ return 'from parent: ' + v
37+ }
3238 }
3339 }
3440 spyOn ( vm , '_bindDir' ) . and . callThrough ( )
@@ -151,27 +157,54 @@ if (_.inBrowser) {
151157 it ( 'param attributes' , function ( ) {
152158 var options = merge ( Vue . options , {
153159 _asComponent : true ,
154- paramAttributes : [ 'a' , 'data-some-attr' , 'some-other-attr' , 'invalid' , 'camelCase' ]
160+ paramAttributes : [
161+ 'a' ,
162+ 'data-some-attr' ,
163+ 'some-other-attr' ,
164+ 'multiple-attrs' ,
165+ 'onetime' ,
166+ 'with-filter' ,
167+ 'camelCase'
168+ ]
155169 } )
156170 var def = Vue . options . directives [ 'with' ]
157171 el . setAttribute ( 'a' , '1' )
158172 el . setAttribute ( 'data-some-attr' , '{{a}}' )
159173 el . setAttribute ( 'some-other-attr' , '2' )
160- el . setAttribute ( 'invalid' , 'a {{b}} c' ) // invalid
174+ el . setAttribute ( 'multiple-attrs' , 'a {{b}} c' )
175+ el . setAttribute ( 'onetime' , '{{*a}}' )
176+ el . setAttribute ( 'with-filter' , '{{a | filter}}' )
161177 transclude ( el , options )
162178 var linker = compile ( el , options )
163179 linker ( vm , el )
164- // should skip literal & invliad
165- expect ( vm . _bindDir . calls . count ( ) ) . toBe ( 1 )
180+ // should skip literals and one-time bindings
181+ expect ( vm . _bindDir . calls . count ( ) ) . toBe ( 3 )
182+ // data-some-attr
166183 var args = vm . _bindDir . calls . argsFor ( 0 )
167184 expect ( args [ 0 ] ) . toBe ( 'with' )
168185 expect ( args [ 1 ] ) . toBe ( null )
169186 expect ( args [ 2 ] . arg ) . toBe ( 'someAttr' )
187+ expect ( args [ 2 ] . expression ) . toBe ( 'a' )
188+ expect ( args [ 3 ] ) . toBe ( def )
189+ // multiple-attrs
190+ args = vm . _bindDir . calls . argsFor ( 1 )
191+ expect ( args [ 0 ] ) . toBe ( 'with' )
192+ expect ( args [ 1 ] ) . toBe ( null )
193+ expect ( args [ 2 ] . arg ) . toBe ( 'multipleAttrs' )
194+ expect ( args [ 2 ] . expression ) . toBe ( '"a "+(b)+" c"' )
170195 expect ( args [ 3 ] ) . toBe ( def )
171- // invalid and camelCase should've warn
172- expect ( _ . warn . calls . count ( ) ) . toBe ( 2 )
173- // literal should've called vm.$set
196+ // with-filter
197+ args = vm . _bindDir . calls . argsFor ( 2 )
198+ expect ( args [ 0 ] ) . toBe ( 'with' )
199+ expect ( args [ 1 ] ) . toBe ( null )
200+ expect ( args [ 2 ] . arg ) . toBe ( 'withFilter' )
201+ expect ( args [ 2 ] . expression ) . toBe ( 'this._applyFilter("filter",[a])' )
202+ expect ( args [ 3 ] ) . toBe ( def )
203+ // camelCase should've warn
204+ expect ( _ . warn . calls . count ( ) ) . toBe ( 1 )
205+ // literal and one time should've called vm.$set
174206 expect ( vm . $set ) . toHaveBeenCalledWith ( 'a' , '1' )
207+ expect ( vm . $set ) . toHaveBeenCalledWith ( 'onetime' , 'from parent: a' )
175208 expect ( vm . $set ) . toHaveBeenCalledWith ( 'someOtherAttr' , '2' )
176209 } )
177210
0 commit comments