11var Vue = require ( '../../../../src/vue' )
22var _ = require ( '../../../../src/util' )
33var transition = require ( '../../../../src/transition' )
4+ var Transition = require ( '../../../../src/transition/transition' )
45
56if ( _ . inBrowser && ! _ . isIE9 ) {
67 describe ( 'Transition' , function ( ) {
@@ -63,14 +64,14 @@ if (_.inBrowser && !_.isIE9) {
6364 } )
6465
6566 it ( 'skip vm still being compiled' , function ( ) {
66- el . __v_trans = { id : 'test' }
67+ el . __v_trans = new Transition ( el , 'test' , null , vm )
6768 transition . apply ( el , 1 , op , vm , cb )
6869 expect ( op ) . toHaveBeenCalled ( )
6970 expect ( cb ) . toHaveBeenCalled ( )
7071 } )
7172
7273 it ( 'skip vm with parent still being compiled' , function ( ) {
73- el . __v_trans = { id : 'test' }
74+ el . __v_trans = new Transition ( el , 'test' , null , vm )
7475 var child = vm . $addChild ( {
7576 el : el
7677 } )
@@ -80,10 +81,10 @@ if (_.inBrowser && !_.isIE9) {
8081 expect ( cb ) . toHaveBeenCalled ( )
8182 } )
8283
83- it ( 'skip when no transition available' , function ( ) {
84+ it ( 'skip when no css transition is available' , function ( ) {
8485 var e = _ . transitionEndEvent
8586 _ . transitionEndEvent = null
86- el . __v_trans = { id : 'test' }
87+ el . __v_trans = new Transition ( el , 'test' , null , vm )
8788 vm . $mount ( el )
8889 transition . apply ( el , 1 , op , vm , cb )
8990 expect ( op ) . toHaveBeenCalled ( )
@@ -134,23 +135,21 @@ if (_.inBrowser && !_.isIE9) {
134135 var vm , el , op , cb
135136 beforeEach ( function ( done ) {
136137 el = document . createElement ( 'div' )
137- el . __v_trans = { }
138138 vm = new Vue ( { el : el } )
139139 op = jasmine . createSpy ( 'css op' )
140140 cb = jasmine . createSpy ( 'css cb' )
141141 document . body . appendChild ( el )
142142 // !IMPORTANT!
143143 // this ensures we force a layout for every test.
144144 _ . nextTick ( done )
145- spyOn ( window , 'getComputedStyle' ) . and . callThrough ( )
146145 } )
147146
148147 afterEach ( function ( ) {
149148 document . body . removeChild ( el )
150149 } )
151150
152151 it ( 'skip on 0s duration (execute right at next frame)' , function ( done ) {
153- el . __v_trans . id = 'test'
152+ el . __v_trans = new Transition ( el , 'test' , null , vm )
154153 el . style . transition =
155154 el . style . WebkitTransition = 'opacity 0s ease'
156155 transition . apply ( el , 1 , op , vm , cb )
@@ -169,7 +168,7 @@ if (_.inBrowser && !_.isIE9) {
169168 } )
170169
171170 it ( 'skip when no transition available' , function ( done ) {
172- el . __v_trans . id = 'test-no-trans'
171+ el . __v_trans = new Transition ( el , 'test-no-trans' , null , vm )
173172 transition . apply ( el , 1 , op , vm , cb )
174173 _ . nextTick ( function ( ) {
175174 expect ( op ) . toHaveBeenCalled ( )
@@ -187,7 +186,7 @@ if (_.inBrowser && !_.isIE9) {
187186
188187 it ( 'transition enter' , function ( done ) {
189188 document . body . removeChild ( el )
190- el . __v_trans . id = 'test'
189+ el . __v_trans = new Transition ( el , 'test' , null , vm )
191190 // inline style
192191 el . style . transition =
193192 el . style . WebkitTransition = 'opacity ' + duration + ' ease'
@@ -207,7 +206,7 @@ if (_.inBrowser && !_.isIE9) {
207206 } )
208207
209208 it ( 'transition leave' , function ( done ) {
210- el . __v_trans . id = 'test'
209+ el . __v_trans = new Transition ( el , 'test' , null , vm )
211210 // cascaded class style
212211 el . classList . add ( 'test' )
213212 // force a layout here so the transition can be triggered
@@ -228,7 +227,7 @@ if (_.inBrowser && !_.isIE9) {
228227
229228 it ( 'animation enter' , function ( done ) {
230229 document . body . removeChild ( el )
231- el . __v_trans . id = 'test-anim'
230+ el . __v_trans = new Transition ( el , 'test-anim' , null , vm )
232231 transition . apply ( el , 1 , function ( ) {
233232 document . body . appendChild ( el )
234233 op ( )
@@ -246,7 +245,7 @@ if (_.inBrowser && !_.isIE9) {
246245 } )
247246
248247 it ( 'animation leave' , function ( done ) {
249- el . __v_trans . id = 'test-anim'
248+ el . __v_trans = new Transition ( el , 'test-anim' , null , vm )
250249 transition . apply ( el , - 1 , op , vm , cb )
251250 _ . nextTick ( function ( ) {
252251 expect ( op ) . not . toHaveBeenCalled ( )
@@ -261,22 +260,22 @@ if (_.inBrowser && !_.isIE9) {
261260 } )
262261 } )
263262
264- it ( 'clean up unfinished callback' , function ( done ) {
265- el . __v_trans . id = 'test'
263+ it ( 'clean up unfinished css callback' , function ( done ) {
264+ el . __v_trans = new Transition ( el , 'test' , null , vm )
266265 el . classList . add ( 'test' )
267266 transition . apply ( el , - 1 , function ( ) {
268267 document . body . removeChild ( el )
269268 } , vm , cb )
270269 // cancel early
271270 _ . nextTick ( function ( ) {
272- expect ( el . __v_trans . callback ) . toBeTruthy ( )
271+ expect ( el . __v_trans . pendingCssCb ) . toBeTruthy ( )
273272 expect ( el . classList . contains ( 'test-leave' ) ) . toBe ( true )
274273 transition . apply ( el , 1 , function ( ) {
275274 document . body . appendChild ( el )
276275 } , vm )
277276 expect ( cb ) . not . toHaveBeenCalled ( )
278277 expect ( el . classList . contains ( 'test-leave' ) ) . toBe ( false )
279- expect ( el . __v_trans . callback ) . toBeNull ( )
278+ expect ( el . __v_trans . pendingCssCb ) . toBeNull ( )
280279 // IMPORTANT
281280 // Let the queue flush finish before enter the next
282281 // test. Don't remove the nextTick.
@@ -285,29 +284,24 @@ if (_.inBrowser && !_.isIE9) {
285284 } )
286285
287286 it ( 'cache transition sniff results' , function ( done ) {
288- el . __v_trans . id = 'test'
287+ el . __v_trans = new Transition ( el , 'test' , null , vm )
289288 el . classList . add ( 'test' )
290289 transition . apply ( el , 1 , op , vm )
291290 _ . nextTick ( function ( ) {
292- expect ( window . getComputedStyle . calls . count ( ) ) . toBe ( 1 )
293- transition . apply ( el , 1 , op , vm )
294- _ . nextTick ( function ( ) {
295- expect ( window . getComputedStyle . calls . count ( ) ) . toBe ( 1 )
296- done ( )
297- } )
291+ expect ( el . __v_trans . typeCache [ 'test-enter' ] ) . not . toBeUndefined ( )
292+ done ( )
298293 } )
299294 } )
300295
301296 } )
302297
303298 describe ( 'JavaScript transitions' , function ( ) {
304299
305- var el , vm , op , cb , def , emitter
300+ var el , vm , op , cb , hooks , emitter
306301 beforeEach ( function ( ) {
307302 emitter = { }
308- def = { }
303+ hooks = { }
309304 el = document . createElement ( 'div' )
310- el . __v_trans = { id : 'test' , fns : def }
311305 document . body . appendChild ( el )
312306 op = jasmine . createSpy ( 'js transition op' )
313307 cb = jasmine . createSpy ( 'js transition cb' )
@@ -320,77 +314,73 @@ if (_.inBrowser && !_.isIE9) {
320314
321315 it ( 'beforeEnter' , function ( ) {
322316 var spy = jasmine . createSpy ( 'js transition beforeEnter' )
323- def . beforeEnter = function ( el ) {
317+ hooks . beforeEnter = function ( el ) {
324318 spy ( this , el )
325319 }
320+ el . __v_trans = new Transition ( el , 'test' , hooks , vm )
326321 transition . apply ( el , 1 , op , vm , cb )
327322 expect ( spy ) . toHaveBeenCalledWith ( vm , el )
328323 } )
329324
330325 it ( 'enter' , function ( ) {
331326 var spy = jasmine . createSpy ( 'js enter' )
332- def . enter = function ( e , done ) {
327+ hooks . enter = function ( e , done ) {
333328 expect ( e ) . toBe ( el )
334329 expect ( op ) . toHaveBeenCalled ( )
335330 done ( )
336331 expect ( cb ) . toHaveBeenCalled ( )
337332 spy ( this )
338333 }
334+ el . __v_trans = new Transition ( el , 'test' , hooks , vm )
339335 transition . apply ( el , 1 , op , vm , cb )
340336 expect ( spy ) . toHaveBeenCalledWith ( vm )
341337 } )
342338
343- it ( 'this context set to el instance' , function ( ) {
344- var spy = jasmine . createSpy ( 'js enter this' )
345- var vm2 = el . __vue__ = { }
346- def . enter = function ( e , done ) {
347- expect ( e ) . toBe ( el )
348- expect ( op ) . toHaveBeenCalled ( )
349- done ( )
350- expect ( cb ) . toHaveBeenCalled ( )
351- spy ( this )
352- }
353- transition . apply ( el , 1 , op , vm , cb )
354- expect ( spy ) . toHaveBeenCalledWith ( vm2 )
355- } )
356-
357339 it ( 'leave' , function ( ) {
358340 var spy = jasmine . createSpy ( 'js leave' )
359- def . leave = function ( e , done ) {
341+ hooks . leave = function ( e , done ) {
360342 expect ( e ) . toBe ( el )
361343 done ( )
362344 expect ( op ) . toHaveBeenCalled ( )
363345 expect ( cb ) . toHaveBeenCalled ( )
364346 spy ( this )
365347 }
348+ el . __v_trans = new Transition ( el , 'test' , hooks , vm )
366349 transition . apply ( el , - 1 , op , vm , cb )
367350 expect ( spy ) . toHaveBeenCalledWith ( vm )
368351 } )
369352
370- it ( 'no def' , function ( ) {
353+ it ( 'no def' , function ( done ) {
354+ el . __v_trans = new Transition ( el , 'test' , null , vm )
371355 transition . apply ( el , 1 , op , vm , cb )
372- expect ( op ) . toHaveBeenCalled ( )
373- expect ( cb ) . toHaveBeenCalled ( )
374- transition . apply ( el , - 1 , op , vm , cb )
375- expect ( op . calls . count ( ) ) . toBe ( 2 )
376- expect ( cb . calls . count ( ) ) . toBe ( 2 )
356+ _ . nextTick ( function ( ) {
357+ expect ( op ) . toHaveBeenCalled ( )
358+ expect ( cb ) . toHaveBeenCalled ( )
359+ transition . apply ( el , - 1 , op , vm , cb )
360+ _ . nextTick ( function ( ) {
361+ expect ( op . calls . count ( ) ) . toBe ( 2 )
362+ expect ( cb . calls . count ( ) ) . toBe ( 2 )
363+ done ( )
364+ } )
365+ } )
377366 } )
378367
379368 it ( 'optional cleanup callback' , function ( done ) {
380369 var cleanupSpy = jasmine . createSpy ( 'js cleanup' )
381370 var leaveSpy = jasmine . createSpy ( 'js leave' )
382- def . enter = function ( el , done ) {
371+ hooks . enter = function ( el , done ) {
383372 var to = setTimeout ( done , 30 )
384373 return function ( ) {
385374 clearTimeout ( to )
386375 cleanupSpy ( )
387376 }
388377 }
389- def . leave = function ( el , done ) {
378+ hooks . leave = function ( el , done ) {
390379 expect ( cleanupSpy ) . toHaveBeenCalled ( )
391380 leaveSpy ( )
392381 done ( )
393382 }
383+ el . __v_trans = new Transition ( el , 'test' , hooks , vm )
394384 transition . apply ( el , 1 , op , vm , cb )
395385 setTimeout ( function ( ) {
396386 transition . apply ( el , - 1 , op , vm )
0 commit comments