@@ -2,6 +2,21 @@ var _ = require('../../../../src/util')
22var def = require ( '../../../../src/directives/style' )
33var Vue = require ( '../../../../src/vue' )
44
5+ function checkPrefixedProp ( prop ) {
6+ var el = document . createElement ( 'div' )
7+ var upper = prop . charAt ( 0 ) . toUpperCase ( ) + prop . slice ( 1 )
8+ if ( ! ( prop in el . style ) ) {
9+ var prefixes = [ 'Webkit' , 'Moz' , 'ms' ]
10+ var i = prefixes . length
11+ while ( i -- ) {
12+ if ( ( prefixes [ i ] + upper ) in el . style ) {
13+ prop = prefixes [ i ] + upper
14+ }
15+ }
16+ }
17+ return prop
18+ }
19+
520if ( _ . inBrowser ) {
621 describe ( 'v-style' , function ( ) {
722
@@ -14,52 +29,53 @@ if (_.inBrowser) {
1429
1530 it ( 'normal with arg' , function ( ) {
1631 dir . arg = 'color'
17- dir . bind ( )
1832 dir . update ( 'red' )
1933 expect ( el . style . color ) . toBe ( 'red' )
2034 } )
2135
2236 it ( 'normal no arg' , function ( ) {
23- dir . bind ( )
2437 dir . update ( 'color:red;' )
2538 expect ( el . style . cssText . replace ( / \s / g, '' ) ) . toBe ( 'color:red;' )
2639 } )
2740
2841 it ( '!important' , function ( ) {
2942 dir . arg = 'color'
30- dir . bind ( )
3143 dir . update ( 'red !important;' )
3244 expect ( el . style . getPropertyPriority ( 'color' ) ) . toBe ( 'important' )
3345 } )
3446
47+ it ( 'camel case' , function ( ) {
48+ dir . arg = 'marginLeft'
49+ dir . update ( '30px' )
50+ expect ( el . style . marginLeft ) . toBe ( '30px' )
51+ } )
52+
53+ it ( 'remove on falsy value' , function ( ) {
54+ el . style . color = 'red'
55+ dir . arg = 'color'
56+ dir . update ( null )
57+ expect ( el . style . color ) . toBe ( '' )
58+ } )
59+
3560 it ( 'auto prefixing' , function ( ) {
36- var spy = el . style . setProperty = jasmine . createSpy ( )
37- dir . arg = '$transform'
38- dir . bind ( )
61+ var prop = checkPrefixedProp ( 'transform' )
62+ dir . arg = 'transform'
3963 var val = 'scale(0.5)'
4064 dir . update ( val )
41- expect ( spy ) . toHaveBeenCalledWith ( 'transform' , val , '' )
42- expect ( spy ) . toHaveBeenCalledWith ( '-ms-transform' , val , '' )
43- expect ( spy ) . toHaveBeenCalledWith ( '-moz-transform' , val , '' )
44- expect ( spy ) . toHaveBeenCalledWith ( '-webkit-transform' , val , '' )
65+ expect ( el . style [ prop ] ) . toBe ( val )
4566 } )
4667
4768 it ( 'update with object' , function ( ) {
48- dir . bind ( )
49- dir . update ( { color : 'red' , 'margin-right' : '30px' } )
69+ dir . update ( { color : 'red' , marginRight : '30px' } )
5070 expect ( el . style . getPropertyValue ( 'color' ) ) . toBe ( 'red' )
5171 expect ( el . style . getPropertyValue ( 'margin-right' ) ) . toBe ( '30px' )
5272 } )
5373
5474 it ( 'update with object and auto prefix' , function ( ) {
55- var spy = el . style . setProperty = jasmine . createSpy ( )
56- dir . bind ( )
57- var scale = 'scale(0.5)' ;
58- dir . update ( { '$transform' : scale } )
59- expect ( spy ) . toHaveBeenCalledWith ( 'transform' , scale , '' )
60- expect ( spy ) . toHaveBeenCalledWith ( '-ms-transform' , scale , '' )
61- expect ( spy ) . toHaveBeenCalledWith ( '-moz-transform' , scale , '' )
62- expect ( spy ) . toHaveBeenCalledWith ( '-webkit-transform' , scale , '' )
75+ var prop = checkPrefixedProp ( 'transform' )
76+ var val = 'scale(0.5)' ;
77+ dir . update ( { transform : val } )
78+ expect ( el . style [ prop ] ) . toBe ( val )
6379 } )
6480
6581 it ( 'updates object deep' , function ( done ) {
0 commit comments