@@ -2,6 +2,21 @@ var _ = require('../../../../src/util')
2
2
var def = require ( '../../../../src/directives/style' )
3
3
var Vue = require ( '../../../../src/vue' )
4
4
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
+
5
20
if ( _ . inBrowser ) {
6
21
describe ( 'v-style' , function ( ) {
7
22
@@ -14,52 +29,53 @@ if (_.inBrowser) {
14
29
15
30
it ( 'normal with arg' , function ( ) {
16
31
dir . arg = 'color'
17
- dir . bind ( )
18
32
dir . update ( 'red' )
19
33
expect ( el . style . color ) . toBe ( 'red' )
20
34
} )
21
35
22
36
it ( 'normal no arg' , function ( ) {
23
- dir . bind ( )
24
37
dir . update ( 'color:red;' )
25
38
expect ( el . style . cssText . replace ( / \s / g, '' ) ) . toBe ( 'color:red;' )
26
39
} )
27
40
28
41
it ( '!important' , function ( ) {
29
42
dir . arg = 'color'
30
- dir . bind ( )
31
43
dir . update ( 'red !important;' )
32
44
expect ( el . style . getPropertyPriority ( 'color' ) ) . toBe ( 'important' )
33
45
} )
34
46
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
+
35
60
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'
39
63
var val = 'scale(0.5)'
40
64
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 )
45
66
} )
46
67
47
68
it ( 'update with object' , function ( ) {
48
- dir . bind ( )
49
- dir . update ( { color : 'red' , 'margin-right' : '30px' } )
69
+ dir . update ( { color : 'red' , marginRight : '30px' } )
50
70
expect ( el . style . getPropertyValue ( 'color' ) ) . toBe ( 'red' )
51
71
expect ( el . style . getPropertyValue ( 'margin-right' ) ) . toBe ( '30px' )
52
72
} )
53
73
54
74
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 )
63
79
} )
64
80
65
81
it ( 'updates object deep' , function ( done ) {
0 commit comments