@@ -3,9 +3,10 @@ describe('UNIT: Transition', function () {
3
3
var transition = require ( 'vue/src/transition' ) ,
4
4
config = require ( 'vue/src/config' ) ,
5
5
codes = transition . codes ,
6
- endEvent = sniffTransitionEndEvent ( ) ,
6
+ endEvents = sniffEndEvents ( ) ,
7
7
enterClass = config . enterClass ,
8
- leaveClass = config . leaveClass
8
+ leaveClass = config . leaveClass ,
9
+ nextTick = Vue . nextTick
9
10
10
11
describe ( 'General' , function ( ) {
11
12
@@ -30,9 +31,9 @@ describe('UNIT: Transition', function () {
30
31
31
32
} )
32
33
33
- describe ( 'CSS class transition ' , function ( ) {
34
+ describe ( 'CSS Transitions ' , function ( ) {
34
35
35
- if ( ! endEvent ) { // IE9 only test case
36
+ if ( ! endEvents . trans ) { // IE9 only test case
36
37
37
38
it ( 'should skip if transition is not available' , function ( ) {
38
39
var c = mockChange ( ) ,
@@ -48,7 +49,7 @@ describe('UNIT: Transition', function () {
48
49
49
50
}
50
51
51
- describe ( 'enter' , function ( ) {
52
+ describe ( 'enter: transition ' , function ( ) {
52
53
53
54
var el = mockEl ( 'css' ) ,
54
55
c = mockChange ( function ( ) {
@@ -61,7 +62,7 @@ describe('UNIT: Transition', function () {
61
62
el . vue_trans_cb = function ( ) {
62
63
cbCalled = true
63
64
}
64
- el . addEventListener ( endEvent , el . vue_trans_cb )
65
+ el . addEventListener ( endEvents . trans , el . vue_trans_cb )
65
66
66
67
it ( 'should add the class before calling changeState()' , function ( ) {
67
68
code = transition ( el , 1 , c . change , compiler )
@@ -70,7 +71,7 @@ describe('UNIT: Transition', function () {
70
71
71
72
it ( 'should remove unfinished leave callback if exists' , function ( ) {
72
73
assert . notOk ( el . vue_trans_cb )
73
- var e = mockHTMLEvent ( endEvent )
74
+ var e = mockHTMLEvent ( endEvents . trans )
74
75
el . dispatchEvent ( e )
75
76
assert . notOk ( cbCalled )
76
77
} )
@@ -85,7 +86,7 @@ describe('UNIT: Transition', function () {
85
86
} )
86
87
87
88
it ( 'should remove the class afterwards' , function ( done ) {
88
- Vue . nextTick ( function ( ) {
89
+ nextTick ( function ( ) {
89
90
assert . notOk ( el . classList . contains ( enterClass ) )
90
91
done ( )
91
92
} )
@@ -101,6 +102,50 @@ describe('UNIT: Transition', function () {
101
102
102
103
} )
103
104
105
+ describe ( 'enter: animation' , function ( ) {
106
+
107
+ var el = mockEl ( 'css' ) ,
108
+ c = mockChange ( function ( ) {
109
+ c . called = true
110
+ assert . notOk ( el . classList . contains ( enterClass ) )
111
+ } ) ,
112
+ compiler = mockCompiler ( ) ,
113
+ code
114
+ // mark it to use CSS animation instead of transition
115
+ el . vue_anim = ''
116
+
117
+ before ( function ( ) {
118
+ document . body . appendChild ( el )
119
+ } )
120
+
121
+ after ( function ( ) {
122
+ document . body . removeChild ( el )
123
+ } )
124
+
125
+ it ( 'should not add enterClass before calling changeState()' , function ( ) {
126
+ code = transition ( el , 1 , c . change , compiler )
127
+ assert . ok ( c . called )
128
+ } )
129
+
130
+ it ( 'should add the class on nextTick' , function ( done ) {
131
+ nextTick ( function ( ) {
132
+ assert . ok ( el . classList . contains ( enterClass ) )
133
+ done ( )
134
+ } )
135
+ } )
136
+
137
+ it ( 'should remove the class when the animation is done' , function ( done ) {
138
+ el . addEventListener ( endEvents . anim , function ( ) {
139
+ assert . notOk ( el . vue_trans_cb )
140
+ assert . notOk ( el . classList . contains ( enterClass ) )
141
+ done ( )
142
+ } )
143
+ var e = mockHTMLEvent ( endEvents . anim )
144
+ el . dispatchEvent ( e )
145
+ } )
146
+
147
+ } )
148
+
104
149
describe ( 'leave' , function ( ) {
105
150
106
151
var el = mockEl ( 'css' ) ,
@@ -112,6 +157,10 @@ describe('UNIT: Transition', function () {
112
157
document . body . appendChild ( el )
113
158
} )
114
159
160
+ after ( function ( ) {
161
+ document . body . removeChild ( el )
162
+ } )
163
+
115
164
it ( 'should call change immediately if el is invisible' , function ( ) {
116
165
var el = mockEl ( 'css' ) ,
117
166
c = mockChange ( ) ,
@@ -132,14 +181,14 @@ describe('UNIT: Transition', function () {
132
181
} )
133
182
134
183
it ( 'should call changeState on transitionend' , function ( ) {
135
- var e = mockHTMLEvent ( endEvent )
184
+ var e = mockHTMLEvent ( endEvents . trans )
136
185
el . dispatchEvent ( e )
137
186
assert . ok ( c . called )
138
187
} )
139
188
140
189
it ( 'should remove the callback after called' , function ( ) {
141
190
assert . notOk ( el . vue_trans_cb )
142
- var e = mockHTMLEvent ( endEvent )
191
+ var e = mockHTMLEvent ( endEvents . trans )
143
192
el . dispatchEvent ( e )
144
193
assert . strictEqual ( c . n , 1 )
145
194
} )
@@ -160,7 +209,7 @@ describe('UNIT: Transition', function () {
160
209
161
210
} )
162
211
163
- describe ( 'JavaScript transition ' , function ( ) {
212
+ describe ( 'JavaScript Transitions ' , function ( ) {
164
213
165
214
it ( 'should skip if correspinding option is not defined' , function ( ) {
166
215
var c = mockChange ( ) ,
@@ -278,19 +327,25 @@ describe('UNIT: Transition', function () {
278
327
}
279
328
}
280
329
281
- function sniffTransitionEndEvent ( ) {
330
+ function sniffEndEvents ( ) {
282
331
var el = document . createElement ( 'vue' ) ,
283
332
defaultEvent = 'transitionend' ,
284
333
events = {
285
334
'transition' : defaultEvent ,
286
- 'MozTransition' : defaultEvent ,
287
- 'WebkitTransition' : 'webkitTransitionEnd'
288
- }
335
+ 'mozTransition' : defaultEvent ,
336
+ 'webkitTransition' : 'webkitTransitionEnd'
337
+ } ,
338
+ ret = { }
289
339
for ( var name in events ) {
290
340
if ( el . style [ name ] !== undefined ) {
291
- return events [ name ]
341
+ ret . trans = events [ name ]
342
+ break
292
343
}
293
344
}
345
+ ret . anim = el . style . animation === ''
346
+ ? 'animationend'
347
+ : 'webkitAnimationEnd'
348
+ return ret
294
349
}
295
350
296
351
} )
0 commit comments