@@ -3,9 +3,10 @@ describe('UNIT: Transition', function () {
33 var transition = require ( 'vue/src/transition' ) ,
44 config = require ( 'vue/src/config' ) ,
55 codes = transition . codes ,
6- endEvent = sniffTransitionEndEvent ( ) ,
6+ endEvents = sniffEndEvents ( ) ,
77 enterClass = config . enterClass ,
8- leaveClass = config . leaveClass
8+ leaveClass = config . leaveClass ,
9+ nextTick = Vue . nextTick
910
1011 describe ( 'General' , function ( ) {
1112
@@ -30,9 +31,9 @@ describe('UNIT: Transition', function () {
3031
3132 } )
3233
33- describe ( 'CSS class transition ' , function ( ) {
34+ describe ( 'CSS Transitions ' , function ( ) {
3435
35- if ( ! endEvent ) { // IE9 only test case
36+ if ( ! endEvents . trans ) { // IE9 only test case
3637
3738 it ( 'should skip if transition is not available' , function ( ) {
3839 var c = mockChange ( ) ,
@@ -48,7 +49,7 @@ describe('UNIT: Transition', function () {
4849
4950 }
5051
51- describe ( 'enter' , function ( ) {
52+ describe ( 'enter: transition ' , function ( ) {
5253
5354 var el = mockEl ( 'css' ) ,
5455 c = mockChange ( function ( ) {
@@ -61,7 +62,7 @@ describe('UNIT: Transition', function () {
6162 el . vue_trans_cb = function ( ) {
6263 cbCalled = true
6364 }
64- el . addEventListener ( endEvent , el . vue_trans_cb )
65+ el . addEventListener ( endEvents . trans , el . vue_trans_cb )
6566
6667 it ( 'should add the class before calling changeState()' , function ( ) {
6768 code = transition ( el , 1 , c . change , compiler )
@@ -70,7 +71,7 @@ describe('UNIT: Transition', function () {
7071
7172 it ( 'should remove unfinished leave callback if exists' , function ( ) {
7273 assert . notOk ( el . vue_trans_cb )
73- var e = mockHTMLEvent ( endEvent )
74+ var e = mockHTMLEvent ( endEvents . trans )
7475 el . dispatchEvent ( e )
7576 assert . notOk ( cbCalled )
7677 } )
@@ -85,7 +86,7 @@ describe('UNIT: Transition', function () {
8586 } )
8687
8788 it ( 'should remove the class afterwards' , function ( done ) {
88- Vue . nextTick ( function ( ) {
89+ nextTick ( function ( ) {
8990 assert . notOk ( el . classList . contains ( enterClass ) )
9091 done ( )
9192 } )
@@ -101,6 +102,50 @@ describe('UNIT: Transition', function () {
101102
102103 } )
103104
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+
104149 describe ( 'leave' , function ( ) {
105150
106151 var el = mockEl ( 'css' ) ,
@@ -112,6 +157,10 @@ describe('UNIT: Transition', function () {
112157 document . body . appendChild ( el )
113158 } )
114159
160+ after ( function ( ) {
161+ document . body . removeChild ( el )
162+ } )
163+
115164 it ( 'should call change immediately if el is invisible' , function ( ) {
116165 var el = mockEl ( 'css' ) ,
117166 c = mockChange ( ) ,
@@ -132,14 +181,14 @@ describe('UNIT: Transition', function () {
132181 } )
133182
134183 it ( 'should call changeState on transitionend' , function ( ) {
135- var e = mockHTMLEvent ( endEvent )
184+ var e = mockHTMLEvent ( endEvents . trans )
136185 el . dispatchEvent ( e )
137186 assert . ok ( c . called )
138187 } )
139188
140189 it ( 'should remove the callback after called' , function ( ) {
141190 assert . notOk ( el . vue_trans_cb )
142- var e = mockHTMLEvent ( endEvent )
191+ var e = mockHTMLEvent ( endEvents . trans )
143192 el . dispatchEvent ( e )
144193 assert . strictEqual ( c . n , 1 )
145194 } )
@@ -160,7 +209,7 @@ describe('UNIT: Transition', function () {
160209
161210 } )
162211
163- describe ( 'JavaScript transition ' , function ( ) {
212+ describe ( 'JavaScript Transitions ' , function ( ) {
164213
165214 it ( 'should skip if correspinding option is not defined' , function ( ) {
166215 var c = mockChange ( ) ,
@@ -278,19 +327,25 @@ describe('UNIT: Transition', function () {
278327 }
279328 }
280329
281- function sniffTransitionEndEvent ( ) {
330+ function sniffEndEvents ( ) {
282331 var el = document . createElement ( 'vue' ) ,
283332 defaultEvent = 'transitionend' ,
284333 events = {
285334 'transition' : defaultEvent ,
286- 'MozTransition' : defaultEvent ,
287- 'WebkitTransition' : 'webkitTransitionEnd'
288- }
335+ 'mozTransition' : defaultEvent ,
336+ 'webkitTransition' : 'webkitTransitionEnd'
337+ } ,
338+ ret = { }
289339 for ( var name in events ) {
290340 if ( el . style [ name ] !== undefined ) {
291- return events [ name ]
341+ ret . trans = events [ name ]
342+ break
292343 }
293344 }
345+ ret . anim = el . style . animation === ''
346+ ? 'animationend'
347+ : 'webkitAnimationEnd'
348+ return ret
294349 }
295350
296351} )
0 commit comments