1
1
var Vue = require ( '../../../../src/vue' )
2
2
var _ = require ( '../../../../src/util' )
3
3
var transition = require ( '../../../../src/transition' )
4
+ var Transition = require ( '../../../../src/transition/transition' )
4
5
5
6
if ( _ . inBrowser && ! _ . isIE9 ) {
6
7
describe ( 'Transition' , function ( ) {
@@ -63,14 +64,14 @@ if (_.inBrowser && !_.isIE9) {
63
64
} )
64
65
65
66
it ( 'skip vm still being compiled' , function ( ) {
66
- el . __v_trans = { id : 'test' }
67
+ el . __v_trans = new Transition ( el , 'test' , null , vm )
67
68
transition . apply ( el , 1 , op , vm , cb )
68
69
expect ( op ) . toHaveBeenCalled ( )
69
70
expect ( cb ) . toHaveBeenCalled ( )
70
71
} )
71
72
72
73
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 )
74
75
var child = vm . $addChild ( {
75
76
el : el
76
77
} )
@@ -80,10 +81,10 @@ if (_.inBrowser && !_.isIE9) {
80
81
expect ( cb ) . toHaveBeenCalled ( )
81
82
} )
82
83
83
- it ( 'skip when no transition available' , function ( ) {
84
+ it ( 'skip when no css transition is available' , function ( ) {
84
85
var e = _ . transitionEndEvent
85
86
_ . transitionEndEvent = null
86
- el . __v_trans = { id : 'test' }
87
+ el . __v_trans = new Transition ( el , 'test' , null , vm )
87
88
vm . $mount ( el )
88
89
transition . apply ( el , 1 , op , vm , cb )
89
90
expect ( op ) . toHaveBeenCalled ( )
@@ -134,23 +135,21 @@ if (_.inBrowser && !_.isIE9) {
134
135
var vm , el , op , cb
135
136
beforeEach ( function ( done ) {
136
137
el = document . createElement ( 'div' )
137
- el . __v_trans = { }
138
138
vm = new Vue ( { el : el } )
139
139
op = jasmine . createSpy ( 'css op' )
140
140
cb = jasmine . createSpy ( 'css cb' )
141
141
document . body . appendChild ( el )
142
142
// !IMPORTANT!
143
143
// this ensures we force a layout for every test.
144
144
_ . nextTick ( done )
145
- spyOn ( window , 'getComputedStyle' ) . and . callThrough ( )
146
145
} )
147
146
148
147
afterEach ( function ( ) {
149
148
document . body . removeChild ( el )
150
149
} )
151
150
152
151
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 )
154
153
el . style . transition =
155
154
el . style . WebkitTransition = 'opacity 0s ease'
156
155
transition . apply ( el , 1 , op , vm , cb )
@@ -169,7 +168,7 @@ if (_.inBrowser && !_.isIE9) {
169
168
} )
170
169
171
170
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 )
173
172
transition . apply ( el , 1 , op , vm , cb )
174
173
_ . nextTick ( function ( ) {
175
174
expect ( op ) . toHaveBeenCalled ( )
@@ -187,7 +186,7 @@ if (_.inBrowser && !_.isIE9) {
187
186
188
187
it ( 'transition enter' , function ( done ) {
189
188
document . body . removeChild ( el )
190
- el . __v_trans . id = 'test'
189
+ el . __v_trans = new Transition ( el , 'test' , null , vm )
191
190
// inline style
192
191
el . style . transition =
193
192
el . style . WebkitTransition = 'opacity ' + duration + ' ease'
@@ -207,7 +206,7 @@ if (_.inBrowser && !_.isIE9) {
207
206
} )
208
207
209
208
it ( 'transition leave' , function ( done ) {
210
- el . __v_trans . id = 'test'
209
+ el . __v_trans = new Transition ( el , 'test' , null , vm )
211
210
// cascaded class style
212
211
el . classList . add ( 'test' )
213
212
// force a layout here so the transition can be triggered
@@ -228,7 +227,7 @@ if (_.inBrowser && !_.isIE9) {
228
227
229
228
it ( 'animation enter' , function ( done ) {
230
229
document . body . removeChild ( el )
231
- el . __v_trans . id = 'test-anim'
230
+ el . __v_trans = new Transition ( el , 'test-anim' , null , vm )
232
231
transition . apply ( el , 1 , function ( ) {
233
232
document . body . appendChild ( el )
234
233
op ( )
@@ -246,7 +245,7 @@ if (_.inBrowser && !_.isIE9) {
246
245
} )
247
246
248
247
it ( 'animation leave' , function ( done ) {
249
- el . __v_trans . id = 'test-anim'
248
+ el . __v_trans = new Transition ( el , 'test-anim' , null , vm )
250
249
transition . apply ( el , - 1 , op , vm , cb )
251
250
_ . nextTick ( function ( ) {
252
251
expect ( op ) . not . toHaveBeenCalled ( )
@@ -261,22 +260,22 @@ if (_.inBrowser && !_.isIE9) {
261
260
} )
262
261
} )
263
262
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 )
266
265
el . classList . add ( 'test' )
267
266
transition . apply ( el , - 1 , function ( ) {
268
267
document . body . removeChild ( el )
269
268
} , vm , cb )
270
269
// cancel early
271
270
_ . nextTick ( function ( ) {
272
- expect ( el . __v_trans . callback ) . toBeTruthy ( )
271
+ expect ( el . __v_trans . pendingCssCb ) . toBeTruthy ( )
273
272
expect ( el . classList . contains ( 'test-leave' ) ) . toBe ( true )
274
273
transition . apply ( el , 1 , function ( ) {
275
274
document . body . appendChild ( el )
276
275
} , vm )
277
276
expect ( cb ) . not . toHaveBeenCalled ( )
278
277
expect ( el . classList . contains ( 'test-leave' ) ) . toBe ( false )
279
- expect ( el . __v_trans . callback ) . toBeNull ( )
278
+ expect ( el . __v_trans . pendingCssCb ) . toBeNull ( )
280
279
// IMPORTANT
281
280
// Let the queue flush finish before enter the next
282
281
// test. Don't remove the nextTick.
@@ -285,29 +284,24 @@ if (_.inBrowser && !_.isIE9) {
285
284
} )
286
285
287
286
it ( 'cache transition sniff results' , function ( done ) {
288
- el . __v_trans . id = 'test'
287
+ el . __v_trans = new Transition ( el , 'test' , null , vm )
289
288
el . classList . add ( 'test' )
290
289
transition . apply ( el , 1 , op , vm )
291
290
_ . 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 ( )
298
293
} )
299
294
} )
300
295
301
296
} )
302
297
303
298
describe ( 'JavaScript transitions' , function ( ) {
304
299
305
- var el , vm , op , cb , def , emitter
300
+ var el , vm , op , cb , hooks , emitter
306
301
beforeEach ( function ( ) {
307
302
emitter = { }
308
- def = { }
303
+ hooks = { }
309
304
el = document . createElement ( 'div' )
310
- el . __v_trans = { id : 'test' , fns : def }
311
305
document . body . appendChild ( el )
312
306
op = jasmine . createSpy ( 'js transition op' )
313
307
cb = jasmine . createSpy ( 'js transition cb' )
@@ -320,77 +314,73 @@ if (_.inBrowser && !_.isIE9) {
320
314
321
315
it ( 'beforeEnter' , function ( ) {
322
316
var spy = jasmine . createSpy ( 'js transition beforeEnter' )
323
- def . beforeEnter = function ( el ) {
317
+ hooks . beforeEnter = function ( el ) {
324
318
spy ( this , el )
325
319
}
320
+ el . __v_trans = new Transition ( el , 'test' , hooks , vm )
326
321
transition . apply ( el , 1 , op , vm , cb )
327
322
expect ( spy ) . toHaveBeenCalledWith ( vm , el )
328
323
} )
329
324
330
325
it ( 'enter' , function ( ) {
331
326
var spy = jasmine . createSpy ( 'js enter' )
332
- def . enter = function ( e , done ) {
327
+ hooks . enter = function ( e , done ) {
333
328
expect ( e ) . toBe ( el )
334
329
expect ( op ) . toHaveBeenCalled ( )
335
330
done ( )
336
331
expect ( cb ) . toHaveBeenCalled ( )
337
332
spy ( this )
338
333
}
334
+ el . __v_trans = new Transition ( el , 'test' , hooks , vm )
339
335
transition . apply ( el , 1 , op , vm , cb )
340
336
expect ( spy ) . toHaveBeenCalledWith ( vm )
341
337
} )
342
338
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
-
357
339
it ( 'leave' , function ( ) {
358
340
var spy = jasmine . createSpy ( 'js leave' )
359
- def . leave = function ( e , done ) {
341
+ hooks . leave = function ( e , done ) {
360
342
expect ( e ) . toBe ( el )
361
343
done ( )
362
344
expect ( op ) . toHaveBeenCalled ( )
363
345
expect ( cb ) . toHaveBeenCalled ( )
364
346
spy ( this )
365
347
}
348
+ el . __v_trans = new Transition ( el , 'test' , hooks , vm )
366
349
transition . apply ( el , - 1 , op , vm , cb )
367
350
expect ( spy ) . toHaveBeenCalledWith ( vm )
368
351
} )
369
352
370
- it ( 'no def' , function ( ) {
353
+ it ( 'no def' , function ( done ) {
354
+ el . __v_trans = new Transition ( el , 'test' , null , vm )
371
355
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
+ } )
377
366
} )
378
367
379
368
it ( 'optional cleanup callback' , function ( done ) {
380
369
var cleanupSpy = jasmine . createSpy ( 'js cleanup' )
381
370
var leaveSpy = jasmine . createSpy ( 'js leave' )
382
- def . enter = function ( el , done ) {
371
+ hooks . enter = function ( el , done ) {
383
372
var to = setTimeout ( done , 30 )
384
373
return function ( ) {
385
374
clearTimeout ( to )
386
375
cleanupSpy ( )
387
376
}
388
377
}
389
- def . leave = function ( el , done ) {
378
+ hooks . leave = function ( el , done ) {
390
379
expect ( cleanupSpy ) . toHaveBeenCalled ( )
391
380
leaveSpy ( )
392
381
done ( )
393
382
}
383
+ el . __v_trans = new Transition ( el , 'test' , hooks , vm )
394
384
transition . apply ( el , 1 , op , vm , cb )
395
385
setTimeout ( function ( ) {
396
386
transition . apply ( el , - 1 , op , vm )
0 commit comments