@@ -257,7 +257,7 @@ o.spec("updateElement", function() {
257
257
258
258
}
259
259
} )
260
- o ( "use style property setter only when cameCase keys" , function ( ) {
260
+ o . only ( "use style property setter only when cameCase keys" , function ( ) {
261
261
var spySetProperty = o . spy ( )
262
262
var spyRemoveProperty = o . spy ( )
263
263
var spyDashed1 = o . spy ( )
@@ -266,26 +266,20 @@ o.spec("updateElement", function() {
266
266
var spyCamelCase1 = o . spy ( )
267
267
var spyCamelCase2 = o . spy ( )
268
268
269
- var f = $window . document . createElement
270
- $window . document . createElement = function ( tag , is ) {
271
- var el = f ( tag , is )
272
-
273
- var style = { }
274
- Object . defineProperties ( style , {
275
- setProperty : { value : spySetProperty } ,
276
- removeProperty : { value : spyRemoveProperty } ,
277
- /* eslint-disable accessor-pairs */
278
- "background-color" : { set : spyDashed1 } ,
279
- "-webkit-border-radius" : { set : spyDashed2 } ,
280
- "--foo" : { set : spyDashed3 } ,
281
- backgroundColor : { set : spyCamelCase1 } ,
282
- color : { set : spyCamelCase2 }
283
- /* eslint-enable accessor-pairs */
284
- } )
285
-
286
- Object . defineProperty ( el , "style" , { value : style } )
287
- return el
288
- }
269
+ render ( root , m ( "a" ) )
270
+ var el = root . firstChild
271
+
272
+ el . style . setProperty = spySetProperty
273
+ el . style . removeProperty = spyRemoveProperty
274
+ Object . defineProperties ( el . style , {
275
+ /* eslint-disable accessor-pairs */
276
+ "background-color" : { set : spyDashed1 } ,
277
+ "-webkit-border-radius" : { set : spyDashed2 } ,
278
+ "--foo" : { set : spyDashed3 } ,
279
+ backgroundColor : { set : spyCamelCase1 } ,
280
+ color : { set : spyCamelCase2 }
281
+ /* eslint-enable accessor-pairs */
282
+ } )
289
283
290
284
// sets dashed properties
291
285
render ( root , m ( "a" , {
@@ -295,6 +289,10 @@ o.spec("updateElement", function() {
295
289
"--foo" : "bar"
296
290
}
297
291
} ) )
292
+ o ( spySetProperty . callCount ) . equals ( 3 )
293
+ o ( spySetProperty . calls [ 0 ] . args ) . deepEquals ( [ "background-color" , "red" ] )
294
+ o ( spySetProperty . calls [ 1 ] . args ) . deepEquals ( [ "-webkit-border-radius" , "10px" ] )
295
+ o ( spySetProperty . calls [ 2 ] . args ) . deepEquals ( [ "--foo" , "bar" ] )
298
296
299
297
// sets camelCase properties and removes dashed properties
300
298
render ( root , m ( "a" , {
@@ -303,32 +301,30 @@ o.spec("updateElement", function() {
303
301
color : "red" ,
304
302
}
305
303
} ) )
304
+ o ( spyCamelCase1 . callCount ) . equals ( 1 )
305
+ o ( spyCamelCase2 . callCount ) . equals ( 1 )
306
+ o ( spyCamelCase1 . calls [ 0 ] . args ) . deepEquals ( [ "green" ] )
307
+ o ( spyCamelCase2 . calls [ 0 ] . args ) . deepEquals ( [ "red" ] )
308
+ o ( spyRemoveProperty . callCount ) . equals ( 3 )
309
+ o ( spyRemoveProperty . calls [ 0 ] . args ) . deepEquals ( [ "background-color" ] )
310
+ o ( spyRemoveProperty . calls [ 1 ] . args ) . deepEquals ( [ "-webkit-border-radius" ] )
311
+ o ( spyRemoveProperty . calls [ 2 ] . args ) . deepEquals ( [ "--foo" ] )
306
312
307
313
// updates "color" and removes "backgroundColor"
308
314
render ( root , m ( "a" , { style : { color : "blue" } } ) )
315
+ o ( spyCamelCase1 . callCount ) . equals ( 2 ) // set and remove
316
+ o ( spyCamelCase2 . callCount ) . equals ( 2 ) // set and update
317
+ o ( spyCamelCase1 . calls [ 1 ] . args ) . deepEquals ( [ "" ] )
318
+ o ( spyCamelCase2 . calls [ 1 ] . args ) . deepEquals ( [ "blue" ] )
309
319
310
- // setProperty (for dashed properties)
320
+ // unchanged by camelCase properties
311
321
o ( spySetProperty . callCount ) . equals ( 3 )
312
- o ( spySetProperty . calls [ 0 ] . args ) . deepEquals ( [ "background-color" , "red" ] )
313
- o ( spySetProperty . calls [ 1 ] . args ) . deepEquals ( [ "-webkit-border-radius" , "10px" ] )
314
- o ( spySetProperty . calls [ 2 ] . args ) . deepEquals ( [ "--foo" , "bar" ] )
315
-
316
- // removeProperty (for dashed properties)
317
322
o ( spyRemoveProperty . callCount ) . equals ( 3 )
318
- o ( spyRemoveProperty . calls [ 0 ] . args ) . deepEquals ( [ "background-color" ] )
319
- o ( spyRemoveProperty . calls [ 1 ] . args ) . deepEquals ( [ "-webkit-border-radius" ] )
320
- o ( spyRemoveProperty . calls [ 2 ] . args ) . deepEquals ( [ "--foo" ] )
321
323
322
- // property setter (for camelCase properties)
324
+ // never calls dashed property setter
323
325
o ( spyDashed1 . callCount ) . equals ( 0 )
324
326
o ( spyDashed2 . callCount ) . equals ( 0 )
325
327
o ( spyDashed3 . callCount ) . equals ( 0 )
326
- o ( spyCamelCase1 . callCount ) . equals ( 2 ) // set and remove
327
- o ( spyCamelCase2 . callCount ) . equals ( 2 ) // set and update
328
- o ( spyCamelCase1 . calls [ 0 ] . args ) . deepEquals ( [ "green" ] )
329
- o ( spyCamelCase1 . calls [ 1 ] . args ) . deepEquals ( [ "" ] )
330
- o ( spyCamelCase2 . calls [ 0 ] . args ) . deepEquals ( [ "red" ] )
331
- o ( spyCamelCase2 . calls [ 1 ] . args ) . deepEquals ( [ "blue" ] )
332
328
} )
333
329
o ( "replaces el" , function ( ) {
334
330
var vnode = m ( "a" )
0 commit comments