@@ -783,9 +783,47 @@ angular.mock.animate = angular.module('ngAnimateMock', ['ng'])
783
783
return queueFn ;
784
784
} ) ;
785
785
786
- $provide . decorator ( '$animate' , [ '$delegate' , '$timeout' , '$browser' , '$$rAF' ,
786
+ $provide . decorator ( '$$animateJs' , [ '$delegate' , function ( $delegate ) {
787
+ var runners = [ ] ;
788
+
789
+ var animateJsConstructor = function ( ) {
790
+ var animator = $delegate . apply ( $delegate , arguments ) ;
791
+ runners . push ( animator ) ;
792
+ return animator ;
793
+ } ;
794
+
795
+ animateJsConstructor . $closeAndFlush = function ( ) {
796
+ runners . forEach ( function ( runner ) {
797
+ runner . end ( ) ;
798
+ } ) ;
799
+ runners = [ ] ;
800
+ } ;
801
+
802
+ return animateJsConstructor ;
803
+ } ] ) ;
804
+
805
+ $provide . decorator ( '$animateCss' , [ '$delegate' , function ( $delegate ) {
806
+ var runners = [ ] ;
807
+
808
+ var animateCssConstructor = function ( element , options ) {
809
+ var animator = $delegate ( element , options ) ;
810
+ runners . push ( animator ) ;
811
+ return animator ;
812
+ } ;
813
+
814
+ animateCssConstructor . $closeAndFlush = function ( ) {
815
+ runners . forEach ( function ( runner ) {
816
+ runner . end ( ) ;
817
+ } ) ;
818
+ runners = [ ] ;
819
+ } ;
820
+
821
+ return animateCssConstructor ;
822
+ } ] ) ;
823
+
824
+ $provide . decorator ( '$animate' , [ '$delegate' , '$timeout' , '$browser' , '$$rAF' , '$animateCss' , '$$animateJs' ,
787
825
'$$forceReflow' , '$$animateAsyncRun' , '$rootScope' ,
788
- function ( $delegate , $timeout , $browser , $$rAF ,
826
+ function ( $delegate , $timeout , $browser , $$rAF , $animateCss , $$animateJs ,
789
827
$$forceReflow , $$animateAsyncRun , $rootScope ) {
790
828
var animate = {
791
829
queue : [ ] ,
@@ -797,7 +835,18 @@ angular.mock.animate = angular.module('ngAnimateMock', ['ng'])
797
835
return $$forceReflow . totalReflows ;
798
836
} ,
799
837
enabled : $delegate . enabled ,
800
- flush : function ( ) {
838
+ closeAndFlush : function ( ) {
839
+ // we allow the flush command to swallow the errors
840
+ // because depending whether CSS or JS animations are
841
+ // used there may not be a RAF flush. The primary flush
842
+ // at the end of this function must throw an exception
843
+ // because it will track if there were pending animations
844
+ this . flush ( true ) ;
845
+ $animateCss . $closeAndFlush ( ) ;
846
+ $$animateJs . $closeAndFlush ( ) ;
847
+ this . flush ( ) ;
848
+ } ,
849
+ flush : function ( hideErrors ) {
801
850
$rootScope . $digest ( ) ;
802
851
803
852
var doNextRun , somethingFlushed = false ;
@@ -814,7 +863,7 @@ angular.mock.animate = angular.module('ngAnimateMock', ['ng'])
814
863
}
815
864
} while ( doNextRun ) ;
816
865
817
- if ( ! somethingFlushed ) {
866
+ if ( ! somethingFlushed && ! hideErrors ) {
818
867
throw new Error ( 'No pending animations ready to be closed or flushed' ) ;
819
868
}
820
869
0 commit comments