@@ -257,6 +257,79 @@ o.spec("updateElement", function() {
257257
258258 }
259259 } )
260+ o ( "use style property setter only when cameCase keys" , function ( ) {
261+ var spySetProperty = o . spy ( )
262+ var spyRemoveProperty = o . spy ( )
263+ var spyDashed1 = o . spy ( )
264+ var spyDashed2 = o . spy ( )
265+ var spyDashed3 = o . spy ( )
266+ var spyCamelCase1 = o . spy ( )
267+ var spyCamelCase2 = o . spy ( )
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+ }
289+
290+ // sets dashed properties
291+ render ( root , m ( "a" , {
292+ style : {
293+ "background-color" : "red" ,
294+ "-webkit-border-radius" : "10px" ,
295+ "--foo" : "bar"
296+ }
297+ } ) )
298+
299+ // sets camelCase properties and removes dashed properties
300+ render ( root , m ( "a" , {
301+ style : {
302+ backgroundColor : "green" ,
303+ color : "red" ,
304+ }
305+ } ) )
306+
307+ // updates "color" and removes "backgroundColor"
308+ render ( root , m ( "a" , { style : { color : "blue" } } ) )
309+
310+ // setProperty (for dashed properties)
311+ 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+ 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+
322+ // property setter (for camelCase properties)
323+ o ( spyDashed1 . callCount ) . equals ( 0 )
324+ o ( spyDashed2 . callCount ) . equals ( 0 )
325+ 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+ } )
260333 o ( "replaces el" , function ( ) {
261334 var vnode = m ( "a" )
262335 var updated = m ( "b" )
0 commit comments