@@ -1189,6 +1189,54 @@ describe("ngAnimate", function() {
1189
1189
expect ( element . hasClass ( 'some-class-add-active' ) ) . toBe ( false ) ;
1190
1190
} ) ) ;
1191
1191
1192
+ it ( "should intelligently cancel former timeouts and close off a series of elements a final timeout" , function ( ) {
1193
+ var cancellations = 0 ;
1194
+ module ( function ( $provide ) {
1195
+ //temporarily override this factory so that the cancellations
1196
+ //are only counted for the the animations
1197
+ //
1198
+ // TODO(matsko): remove this line once rAF callbacks are merged
1199
+ $provide . value ( '$$asyncQueueBuffer' , angular . noop ) ;
1200
+ $provide . decorator ( '$timeout' , function ( $delegate ) {
1201
+ var _cancel = $delegate . cancel ;
1202
+ $delegate . cancel = function ( ) {
1203
+ cancellations ++ ;
1204
+ return _cancel . apply ( $delegate , arguments ) ;
1205
+ } ;
1206
+ return $delegate ;
1207
+ } ) ;
1208
+ } )
1209
+ inject ( function ( $animate , $rootScope , $compile , $sniffer , $timeout ) {
1210
+ if ( ! $sniffer . transitions ) return ;
1211
+
1212
+ ss . addRule ( '.animate-me' , '-webkit-transition:1s linear all;' +
1213
+ 'transition:1s linear all;' ) ;
1214
+
1215
+ element = $compile ( html ( '<div><div class="animate-me" ng-repeat="item in items"></div></div>' ) ) ( $rootScope ) ;
1216
+
1217
+ $rootScope . items = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ;
1218
+ var totalOperations = $rootScope . items . length ;
1219
+
1220
+ $rootScope . $digest ( ) ;
1221
+
1222
+ $rootScope . items = [ 0 ] ;
1223
+ $animate . triggerReflow ( ) ;
1224
+ $timeout . flush ( 1500 ) ;
1225
+
1226
+ expect ( cancellations ) . toBeLessThan ( totalOperations ) ;
1227
+ expect ( element . children ( ) . length ) . toBe ( 10 ) ;
1228
+ cancellations = 0 ;
1229
+
1230
+ $rootScope . items = [ 1 ] ;
1231
+ $rootScope . $digest ( ) ;
1232
+
1233
+ $animate . triggerReflow ( ) ;
1234
+ $timeout . flush ( 1500 ) ;
1235
+ expect ( element . children ( ) . length ) . toBe ( 1 ) ;
1236
+ expect ( cancellations ) . toBeLessThan ( totalOperations ) ;
1237
+ } ) ;
1238
+ } ) ;
1239
+
1192
1240
it ( "apply a closing timeout with respect to a staggering animation" ,
1193
1241
inject ( function ( $animate , $rootScope , $compile , $sniffer , $timeout ) {
1194
1242
0 commit comments