@@ -2673,10 +2673,16 @@ describe("ngAnimate", function() {
2673
2673
beforeAddClass : function ( element , className , done ) {
2674
2674
currentAnimation = 'addClass' ;
2675
2675
currentFn = done ;
2676
+ return function ( cancelled ) {
2677
+ currentAnimation = cancelled ? null : currentAnimation ;
2678
+ }
2676
2679
} ,
2677
2680
beforeRemoveClass : function ( element , className , done ) {
2678
2681
currentAnimation = 'removeClass' ;
2679
2682
currentFn = done ;
2683
+ return function ( cancelled ) {
2684
+ currentAnimation = cancelled ? null : currentAnimation ;
2685
+ }
2680
2686
}
2681
2687
} ;
2682
2688
} ) ;
@@ -2690,10 +2696,12 @@ describe("ngAnimate", function() {
2690
2696
expect ( currentAnimation ) . toBe ( 'addClass' ) ;
2691
2697
currentFn ( ) ;
2692
2698
2699
+ currentAnimation = null ;
2700
+
2693
2701
$animate . removeClass ( element , 'on' ) ;
2694
2702
$animate . addClass ( element , 'on' ) ;
2695
2703
2696
- expect ( currentAnimation ) . toBe ( 'addClass' ) ;
2704
+ expect ( currentAnimation ) . toBe ( null ) ;
2697
2705
} ) ;
2698
2706
} ) ;
2699
2707
@@ -3113,5 +3121,51 @@ describe("ngAnimate", function() {
3113
3121
$timeout . flush ( 1 ) ;
3114
3122
expect ( ready ) . toBe ( true ) ;
3115
3123
} ) ) ;
3124
+
3125
+ it ( 'should avoid skip animations if the same CSS class is added / removed synchronously before the reflow kicks in' ,
3126
+ inject ( function ( $sniffer , $compile , $rootScope , $rootElement , $animate , $timeout ) {
3127
+
3128
+ if ( ! $sniffer . transitions ) return ;
3129
+
3130
+ ss . addRule ( '.water-class' , '-webkit-transition:2s linear all;' +
3131
+ 'transition:2s linear all;' ) ;
3132
+
3133
+ $animate . enabled ( true ) ;
3134
+
3135
+ var element = $compile ( '<div class="water-class on"></div>' ) ( $rootScope ) ;
3136
+ $rootElement . append ( element ) ;
3137
+ jqLite ( $document [ 0 ] . body ) . append ( $rootElement ) ;
3138
+
3139
+ var signature = '' ;
3140
+ $animate . removeClass ( element , 'on' , function ( ) {
3141
+ signature += 'A' ;
3142
+ } ) ;
3143
+ $animate . addClass ( element , 'on' , function ( ) {
3144
+ signature += 'B' ;
3145
+ } ) ;
3146
+
3147
+ $timeout . flush ( 1 ) ;
3148
+ expect ( signature ) . toBe ( 'AB' ) ;
3149
+
3150
+ signature = '' ;
3151
+ $animate . removeClass ( element , 'on' , function ( ) {
3152
+ signature += 'A' ;
3153
+ } ) ;
3154
+ $animate . addClass ( element , 'on' , function ( ) {
3155
+ signature += 'B' ;
3156
+ } ) ;
3157
+ $animate . removeClass ( element , 'on' , function ( ) {
3158
+ signature += 'C' ;
3159
+ } ) ;
3160
+
3161
+ $timeout . flush ( 1 ) ;
3162
+ expect ( signature ) . toBe ( 'AB' ) ;
3163
+
3164
+ $timeout . flush ( 10 ) ;
3165
+ browserTrigger ( element , 'transitionend' , { timeStamp : Date . now ( ) , elapsedTime : 2000 } ) ;
3166
+ $timeout . flush ( 1 ) ;
3167
+
3168
+ expect ( signature ) . toBe ( 'ABC' ) ;
3169
+ } ) ) ;
3116
3170
} ) ;
3117
3171
} ) ;
0 commit comments