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