@@ -1181,6 +1181,49 @@ describe("ngAnimate", function() {
1181
1181
expect ( element . hasClass ( 'some-class-add-active' ) ) . toBe ( false ) ;
1182
1182
} ) ) ;
1183
1183
1184
+ it ( "should intelligently cancel former timeouts and close off a series of elements a final timeout" , function ( ) {
1185
+ var cancellations = 0 ;
1186
+ module ( function ( $provide ) {
1187
+ $provide . decorator ( '$timeout' , function ( $delegate ) {
1188
+ var _cancel = $delegate . cancel ;
1189
+ $delegate . cancel = function ( ) {
1190
+ cancellations ++ ;
1191
+ return _cancel . apply ( $delegate , arguments ) ;
1192
+ } ;
1193
+ return $delegate ;
1194
+ } ) ;
1195
+ } )
1196
+ inject ( function ( $animate , $rootScope , $compile , $sniffer , $timeout ) {
1197
+ if ( ! $sniffer . transitions ) return ;
1198
+
1199
+ ss . addRule ( '.animate-me' , '-webkit-transition:1s linear all;' +
1200
+ 'transition:1s linear all;' ) ;
1201
+
1202
+ element = $compile ( html ( '<div><div class="animate-me" ng-repeat="item in items"></div></div>' ) ) ( $rootScope ) ;
1203
+
1204
+ $rootScope . items = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ;
1205
+ var totalOperations = $rootScope . items . length ;
1206
+
1207
+ $rootScope . $digest ( ) ;
1208
+
1209
+ $rootScope . items = [ 0 ] ;
1210
+ $animate . triggerReflow ( ) ;
1211
+ $timeout . flush ( 1500 ) ;
1212
+
1213
+ expect ( cancellations ) . toBeLessThan ( totalOperations ) ;
1214
+ expect ( element . children ( ) . length ) . toBe ( 10 ) ;
1215
+ cancellations = 0 ;
1216
+
1217
+ $rootScope . items = [ 1 ] ;
1218
+ $rootScope . $digest ( ) ;
1219
+
1220
+ $animate . triggerReflow ( ) ;
1221
+ $timeout . flush ( 1500 ) ;
1222
+ expect ( element . children ( ) . length ) . toBe ( 1 ) ;
1223
+ expect ( cancellations ) . toBeLessThan ( totalOperations ) ;
1224
+ } ) ;
1225
+ } ) ;
1226
+
1184
1227
it ( "apply a closing timeout with respect to a staggering animation" ,
1185
1228
inject ( function ( $animate , $rootScope , $compile , $sniffer , $timeout ) {
1186
1229
0 commit comments