@@ -149,30 +149,40 @@ if (_.inBrowser && !_.isIE9) {
149149 document . body . removeChild ( el )
150150 } )
151151
152- it ( 'skip on 0s duration' , function ( ) {
152+ it ( 'skip on 0s duration (execute right at next frame) ' , function ( done ) {
153153 el . __v_trans . id = 'test'
154154 el . style . transition =
155155 el . style . WebkitTransition = 'opacity 0s ease'
156156 transition . apply ( el , 1 , op , vm , cb )
157- expect ( op ) . toHaveBeenCalled ( )
158- expect ( cb ) . toHaveBeenCalled ( )
159- expect ( el . classList . contains ( 'test-enter' ) ) . toBe ( false )
160- transition . apply ( el , - 1 , op , vm , cb )
161- expect ( op . calls . count ( ) ) . toBe ( 2 )
162- expect ( cb . calls . count ( ) ) . toBe ( 2 )
163- expect ( el . classList . contains ( 'test-leave' ) ) . toBe ( false )
157+ _ . nextTick ( function ( ) {
158+ expect ( op ) . toHaveBeenCalled ( )
159+ expect ( cb ) . toHaveBeenCalled ( )
160+ expect ( el . classList . contains ( 'test-enter' ) ) . toBe ( false )
161+ transition . apply ( el , - 1 , op , vm , cb )
162+ _ . nextTick ( function ( ) {
163+ expect ( op . calls . count ( ) ) . toBe ( 2 )
164+ expect ( cb . calls . count ( ) ) . toBe ( 2 )
165+ expect ( el . classList . contains ( 'test-leave' ) ) . toBe ( false )
166+ done ( )
167+ } )
168+ } )
164169 } )
165170
166- it ( 'skip when no transition available' , function ( ) {
171+ it ( 'skip when no transition available' , function ( done ) {
167172 el . __v_trans . id = 'test-no-trans'
168173 transition . apply ( el , 1 , op , vm , cb )
169- expect ( op ) . toHaveBeenCalled ( )
170- expect ( cb ) . toHaveBeenCalled ( )
171- expect ( el . classList . contains ( 'test-no-trans-enter' ) ) . toBe ( false )
172- transition . apply ( el , - 1 , op , vm , cb )
173- expect ( op . calls . count ( ) ) . toBe ( 2 )
174- expect ( cb . calls . count ( ) ) . toBe ( 2 )
175- expect ( el . classList . contains ( 'test-no-trans-leave' ) ) . toBe ( false )
174+ _ . nextTick ( function ( ) {
175+ expect ( op ) . toHaveBeenCalled ( )
176+ expect ( cb ) . toHaveBeenCalled ( )
177+ expect ( el . classList . contains ( 'test-no-trans-enter' ) ) . toBe ( false )
178+ transition . apply ( el , - 1 , op , vm , cb )
179+ _ . nextTick ( function ( ) {
180+ expect ( op . calls . count ( ) ) . toBe ( 2 )
181+ expect ( cb . calls . count ( ) ) . toBe ( 2 )
182+ expect ( el . classList . contains ( 'test-no-trans-leave' ) ) . toBe ( false )
183+ done ( )
184+ } )
185+ } )
176186 } )
177187
178188 it ( 'transition enter' , function ( done ) {
@@ -200,19 +210,21 @@ if (_.inBrowser && !_.isIE9) {
200210 el . __v_trans . id = 'test'
201211 // cascaded class style
202212 el . classList . add ( 'test' )
203- // wait a frame: Chrome Android 37 doesn't trigger
204- // transition if we apply the leave class in the
205- // same frame.
213+ // wait a tick before applying the transition
214+ // because doing so in the same frame won't trigger
215+ // transition
206216 _ . nextTick ( function ( ) {
207217 transition . apply ( el , - 1 , op , vm , cb )
208- expect ( op ) . not . toHaveBeenCalled ( )
209- expect ( cb ) . not . toHaveBeenCalled ( )
210- expect ( el . classList . contains ( 'test-leave' ) ) . toBe ( true )
211- _ . on ( el , _ . transitionEndEvent , function ( ) {
212- expect ( op ) . toHaveBeenCalled ( )
213- expect ( cb ) . toHaveBeenCalled ( )
214- expect ( el . classList . contains ( 'test-leave' ) ) . toBe ( false )
215- done ( )
218+ _ . nextTick ( function ( ) {
219+ expect ( op ) . not . toHaveBeenCalled ( )
220+ expect ( cb ) . not . toHaveBeenCalled ( )
221+ expect ( el . classList . contains ( 'test-leave' ) ) . toBe ( true )
222+ _ . on ( el , _ . transitionEndEvent , function ( ) {
223+ expect ( op ) . toHaveBeenCalled ( )
224+ expect ( cb ) . toHaveBeenCalled ( )
225+ expect ( el . classList . contains ( 'test-leave' ) ) . toBe ( false )
226+ done ( )
227+ } )
216228 } )
217229 } )
218230 } )
@@ -224,27 +236,31 @@ if (_.inBrowser && !_.isIE9) {
224236 document . body . appendChild ( el )
225237 op ( )
226238 } , vm , cb )
227- expect ( op ) . toHaveBeenCalled ( )
228- expect ( cb ) . not . toHaveBeenCalled ( )
229- expect ( el . classList . contains ( 'test-anim-enter' ) ) . toBe ( true )
230- _ . on ( el , _ . animationEndEvent , function ( ) {
231- expect ( el . classList . contains ( 'test-anim-enter' ) ) . toBe ( false )
232- expect ( cb ) . toHaveBeenCalled ( )
233- done ( )
239+ _ . nextTick ( function ( ) {
240+ expect ( op ) . toHaveBeenCalled ( )
241+ expect ( cb ) . not . toHaveBeenCalled ( )
242+ expect ( el . classList . contains ( 'test-anim-enter' ) ) . toBe ( true )
243+ _ . on ( el , _ . animationEndEvent , function ( ) {
244+ expect ( el . classList . contains ( 'test-anim-enter' ) ) . toBe ( false )
245+ expect ( cb ) . toHaveBeenCalled ( )
246+ done ( )
247+ } )
234248 } )
235249 } )
236250
237251 it ( 'animation leave' , function ( done ) {
238252 el . __v_trans . id = 'test-anim'
239253 transition . apply ( el , - 1 , op , vm , cb )
240- expect ( op ) . not . toHaveBeenCalled ( )
241- expect ( cb ) . not . toHaveBeenCalled ( )
242- expect ( el . classList . contains ( 'test-anim-leave' ) ) . toBe ( true )
243- _ . on ( el , _ . animationEndEvent , function ( ) {
244- expect ( op ) . toHaveBeenCalled ( )
245- expect ( cb ) . toHaveBeenCalled ( )
246- expect ( el . classList . contains ( 'test-anim-leave' ) ) . toBe ( false )
247- done ( )
254+ _ . nextTick ( function ( ) {
255+ expect ( op ) . not . toHaveBeenCalled ( )
256+ expect ( cb ) . not . toHaveBeenCalled ( )
257+ expect ( el . classList . contains ( 'test-anim-leave' ) ) . toBe ( true )
258+ _ . on ( el , _ . animationEndEvent , function ( ) {
259+ expect ( op ) . toHaveBeenCalled ( )
260+ expect ( cb ) . toHaveBeenCalled ( )
261+ expect ( el . classList . contains ( 'test-anim-leave' ) ) . toBe ( false )
262+ done ( )
263+ } )
248264 } )
249265 } )
250266
@@ -254,27 +270,35 @@ if (_.inBrowser && !_.isIE9) {
254270 transition . apply ( el , - 1 , function ( ) {
255271 document . body . removeChild ( el )
256272 } , vm , cb )
257- expect ( el . __v_trans . callback ) . toBeTruthy ( )
258273 // cancel early
259274 _ . nextTick ( function ( ) {
275+ expect ( el . __v_trans . callback ) . toBeTruthy ( )
260276 expect ( el . classList . contains ( 'test-leave' ) ) . toBe ( true )
261277 transition . apply ( el , 1 , function ( ) {
262278 document . body . appendChild ( el )
263279 } , vm )
264280 expect ( cb ) . not . toHaveBeenCalled ( )
265281 expect ( el . classList . contains ( 'test-leave' ) ) . toBe ( false )
266282 expect ( el . __v_trans . callback ) . toBeNull ( )
267- done ( )
283+ // IMPORTANT
284+ // Let the queue flush finish before enter the next
285+ // test. Don't remove the nextTick.
286+ _ . nextTick ( done )
268287 } )
269288 } )
270289
271- it ( 'cache transition sniff results' , function ( ) {
290+ it ( 'cache transition sniff results' , function ( done ) {
272291 el . __v_trans . id = 'test'
273292 el . classList . add ( 'test' )
274293 transition . apply ( el , 1 , op , vm )
275- expect ( window . getComputedStyle . calls . count ( ) ) . toBe ( 1 )
276- transition . apply ( el , 1 , op , vm )
277- expect ( window . getComputedStyle . calls . count ( ) ) . toBe ( 1 )
294+ _ . nextTick ( function ( ) {
295+ expect ( window . getComputedStyle . calls . count ( ) ) . toBe ( 1 )
296+ transition . apply ( el , 1 , op , vm )
297+ _ . nextTick ( function ( ) {
298+ expect ( window . getComputedStyle . calls . count ( ) ) . toBe ( 1 )
299+ done ( )
300+ } )
301+ } )
278302 } )
279303
280304 } )
0 commit comments