@@ -29,6 +29,12 @@ if (_.inBrowser) {
29
29
} ,
30
30
$interpolate : function ( value ) {
31
31
return data [ value ]
32
+ } ,
33
+ $parent : {
34
+ _directives : [ ] ,
35
+ $get : function ( v ) {
36
+ return 'from parent: ' + v
37
+ }
32
38
}
33
39
}
34
40
spyOn ( vm , '_bindDir' ) . and . callThrough ( )
@@ -151,27 +157,54 @@ if (_.inBrowser) {
151
157
it ( 'param attributes' , function ( ) {
152
158
var options = merge ( Vue . options , {
153
159
_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
+ ]
155
169
} )
156
170
var def = Vue . options . directives [ 'with' ]
157
171
el . setAttribute ( 'a' , '1' )
158
172
el . setAttribute ( 'data-some-attr' , '{{a}}' )
159
173
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}}' )
161
177
transclude ( el , options )
162
178
var linker = compile ( el , options )
163
179
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
166
183
var args = vm . _bindDir . calls . argsFor ( 0 )
167
184
expect ( args [ 0 ] ) . toBe ( 'with' )
168
185
expect ( args [ 1 ] ) . toBe ( null )
169
186
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"' )
170
195
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
174
206
expect ( vm . $set ) . toHaveBeenCalledWith ( 'a' , '1' )
207
+ expect ( vm . $set ) . toHaveBeenCalledWith ( 'onetime' , 'from parent: a' )
175
208
expect ( vm . $set ) . toHaveBeenCalledWith ( 'someOtherAttr' , '2' )
176
209
} )
177
210
0 commit comments