1
1
'use strict' ;
2
2
3
- describe ( '$$animation' , function ( ) {
3
+ ddescribe ( '$$animation' , function ( ) {
4
4
5
5
beforeEach ( module ( 'ngAnimate' ) ) ;
6
6
@@ -14,14 +14,15 @@ describe('$$animation', function() {
14
14
} ) ) ;
15
15
16
16
it ( "should not run an animation if there are no drivers" ,
17
- inject ( function ( $$animation , $$rAF ) {
17
+ inject ( function ( $$animation , $$rAF , $rootScope ) {
18
18
19
19
element = jqLite ( '<div></div>' ) ;
20
20
var done = false ;
21
21
$$animation ( element , 'someEvent' ) . then ( function ( ) {
22
22
done = true ;
23
23
} ) ;
24
24
$$rAF . flush ( ) ;
25
+ $rootScope . $digest ( ) ;
25
26
expect ( done ) . toBe ( true ) ;
26
27
} ) ) ;
27
28
@@ -40,6 +41,7 @@ describe('$$animation', function() {
40
41
} ) ;
41
42
$rootScope . $digest ( ) ;
42
43
$$rAF . flush ( ) ;
44
+ $rootScope . $digest ( ) ;
43
45
expect ( done ) . toBe ( true ) ;
44
46
} ) ;
45
47
} ) ;
@@ -195,6 +197,7 @@ describe('$$animation', function() {
195
197
// the resolve/rejection digest
196
198
$rootScope . $digest ( ) ;
197
199
$$rAF . flush ( ) ;
200
+ $rootScope . $digest ( ) ;
198
201
199
202
expect ( status ) . toBe ( event ) ;
200
203
} ) ;
@@ -207,13 +210,12 @@ describe('$$animation', function() {
207
210
208
211
module ( function ( $$animationProvider , $provide ) {
209
212
$$animationProvider . drivers . push ( 'actualDriver' ) ;
210
- $provide . factory ( 'actualDriver' , function ( $qRaf , $$ animateRunner) {
213
+ $provide . factory ( 'actualDriver' , function ( $animateRunner ) {
211
214
return function ( ) {
212
215
return {
213
216
start : function ( ) {
214
217
log . push ( 'start' ) ;
215
- var promise = $qRaf . when ( true ) ;
216
- return $$animateRunner ( promise , {
218
+ return new $animateRunner ( {
217
219
end : function ( ) {
218
220
log . push ( 'end' ) ;
219
221
} ,
@@ -249,12 +251,11 @@ describe('$$animation', function() {
249
251
capturedAnimation = null ;
250
252
251
253
$$animationProvider . drivers . push ( 'interceptorDriver' ) ;
252
- $provide . factory ( 'interceptorDriver' , function ( $q , $$ animateRunner) {
254
+ $provide . factory ( 'interceptorDriver' , function ( $animateRunner ) {
253
255
return function ( details ) {
254
256
captureLog . push ( capturedAnimation = details ) ; //only one param is passed into the driver
255
257
return function ( ) {
256
- var runner = $q . when ( true ) ;
257
- return $$animateRunner ( runner , {
258
+ return new $animateRunner ( {
258
259
end : runnerEvent ( 'end' ) ,
259
260
cancel : runnerEvent ( 'cancel' )
260
261
} ) ;
@@ -302,24 +303,34 @@ describe('$$animation', function() {
302
303
} ) ;
303
304
} ) ;
304
305
305
- it ( 'should patch the runner methods to the ones provided by the driver when the animation starts' ,
306
- inject ( function ( $$animation , $rootScope ) {
307
-
308
- var runner = $$animation ( element , 'someEvent' ) ;
309
- expect ( runner . end ) . not . toEqual ( noop ) ;
310
- expect ( runner . cancel ) . not . toEqual ( noop ) ;
311
-
312
- var oldEnd = runner . end ;
313
- var oldCancel = runner . cancel ;
314
-
315
- $rootScope . $digest ( ) ;
306
+ they ( 'should update the runner methods to the ones provided by the driver when the animation starts' ,
307
+ [ 'end' , 'cancel' ] , function ( method ) {
316
308
317
- expect ( oldEnd ) . not . toBe ( runner . end ) ;
318
- expect ( oldCancel ) . not . toBe ( runner . cancel ) ;
309
+ var spy = jasmine . createSpy ( ) ;
310
+ module ( function ( $$animationProvider , $provide ) {
311
+ $$animationProvider . drivers . push ( 'animalDriver' ) ;
312
+ $provide . factory ( 'animalDriver' , function ( $animateRunner ) {
313
+ return function ( ) {
314
+ return function ( ) {
315
+ var data = { } ;
316
+ data [ method ] = spy ;
317
+ return new $animateRunner ( data ) ;
318
+ } ;
319
+ } ;
320
+ } ) ;
321
+ } ) ;
322
+ inject ( function ( $$animation , $rootScope , $rootElement ) {
323
+ var r1 = $$animation ( element , 'someEvent' ) ;
324
+ r1 [ method ] ( ) ;
325
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
326
+ $rootScope . $digest ( ) ; // this clears the digest which cleans up the mess
319
327
320
- runner . end ( ) ;
321
- expect ( runnerLog ) . toEqual ( [ 'end' ] ) ;
322
- } ) ) ;
328
+ var r2 = $$animation ( element , 'otherEvent' ) ;
329
+ $rootScope . $digest ( ) ;
330
+ r2 [ method ] ( ) ;
331
+ expect ( spy ) . toHaveBeenCalled ( ) ;
332
+ } ) ;
333
+ } ) ;
323
334
324
335
it ( 'should not start the animation if the element is removed from the DOM before the postDigest kicks in' ,
325
336
inject ( function ( $$animation ) {
@@ -559,8 +570,6 @@ describe('$$animation', function() {
559
570
var runner2 = $$animation ( toElement , 'enter' ) ;
560
571
561
572
expect ( runner1 ) . not . toBe ( runner2 ) ;
562
- expect ( runner1 . end ) . not . toBe ( runner2 . end ) ;
563
- expect ( runner1 . cancel ) . not . toBe ( runner2 . cancel ) ;
564
573
565
574
fromAnchors [ 0 ] . attr ( 'ng-animate-ref' , 'abc' ) ;
566
575
toAnchors [ 0 ] . attr ( 'ng-animate-ref' , 'abc' ) ;
@@ -661,15 +670,13 @@ describe('$$animation', function() {
661
670
element = jqLite ( '<div></div>' ) ;
662
671
parent = jqLite ( '<div></div>' ) ;
663
672
664
- return function ( $$ animateRunner , $q , $rootElement , $document ) {
673
+ return function ( $animateRunner , $q , $rootElement , $document ) {
665
674
jqLite ( $document [ 0 ] . body ) . append ( $rootElement ) ;
666
675
$rootElement . append ( parent ) ;
667
676
668
677
mockedDriverFn = function ( element , method , options , domOperation ) {
669
678
return function ( ) {
670
- defered = $q . defer ( ) ;
671
- runner = $$animateRunner ( defered . promise ) ;
672
- return runner ;
679
+ return runner = new $animateRunner ( ) ;
673
680
} ;
674
681
} ;
675
682
} ;
@@ -686,7 +693,7 @@ describe('$$animation', function() {
686
693
expect ( element ) . toHaveClass ( 'temporary' ) ;
687
694
expect ( element ) . toHaveClass ( 'fudge' ) ;
688
695
689
- defered . resolve ( ) ;
696
+ runner . end ( ) ;
690
697
$rootScope . $digest ( ) ;
691
698
692
699
expect ( element ) . not . toHaveClass ( 'temporary' ) ;
@@ -700,7 +707,7 @@ describe('$$animation', function() {
700
707
$rootScope . $digest ( ) ;
701
708
expect ( element ) . toHaveClass ( 'ng-animate' ) ;
702
709
703
- defered . resolve ( ) ;
710
+ runner . end ( ) ;
704
711
$rootScope . $digest ( ) ;
705
712
706
713
expect ( element ) . not . toHaveClass ( 'ng-animate' ) ;
@@ -719,7 +726,7 @@ describe('$$animation', function() {
719
726
$rootScope . $digest ( ) ;
720
727
721
728
expect ( domOperationFired ) . toBeFalsy ( ) ;
722
- defered . resolve ( ) ;
729
+ runner . end ( ) ;
723
730
$rootScope . $digest ( ) ;
724
731
725
732
expect ( domOperationFired ) . toBeTruthy ( ) ;
@@ -762,6 +769,7 @@ describe('$$animation', function() {
762
769
$rootScope . $digest ( ) ; //runs the animation
763
770
$rootScope . $digest ( ) ; //flushes the step code
764
771
$$rAF . flush ( ) ; //runs the $$animation promise
772
+ $rootScope . $digest ( ) ; //the runner promise
765
773
766
774
expect ( completed ) . toBe ( true ) ;
767
775
expect ( element . css ( 'background' ) ) . toBe ( 'blue' ) ;
@@ -813,6 +821,7 @@ describe('$$animation', function() {
813
821
$rootScope . $digest ( ) ; //runs the animation
814
822
$rootScope . $digest ( ) ; //flushes the step code
815
823
$$rAF . flush ( ) ; //runs the $$animation promise
824
+ $rootScope . $digest ( ) ; //the runner promise
816
825
817
826
expect ( completed ) . toBe ( true ) ;
818
827
expect ( element ) . toHaveClass ( 'one' ) ;
0 commit comments