@@ -1301,24 +1301,43 @@ describe("ngAnimate", function() {
1301
1301
} ) ) ;
1302
1302
1303
1303
it ( "should intelligently cancel former timeouts and close off a series of elements a final timeout" , function ( ) {
1304
- var cancellations = 0 ;
1304
+ var _now , currentTimestamp , cancellations = 0 ;
1305
1305
module ( function ( $provide ) {
1306
+ _now = Date . now ;
1307
+ currentTimestamp = _now ( ) ;
1308
+ Date . now = function ( ) {
1309
+ return currentTimestamp ;
1310
+ } ;
1311
+
1306
1312
$provide . decorator ( '$timeout' , function ( $delegate ) {
1307
1313
var _cancel = $delegate . cancel ;
1308
- $delegate . cancel = function ( ) {
1309
- cancellations ++ ;
1310
- return _cancel . apply ( $delegate , arguments ) ;
1314
+ $delegate . cancel = function ( timer ) {
1315
+ if ( timer ) {
1316
+ cancellations ++ ;
1317
+ return _cancel . apply ( $delegate , arguments ) ;
1318
+ }
1311
1319
} ;
1312
1320
return $delegate ;
1313
1321
} ) ;
1314
1322
} )
1315
1323
inject ( function ( $animate , $rootScope , $compile , $sniffer , $timeout ) {
1316
1324
if ( ! $sniffer . transitions ) return ;
1317
1325
1318
- ss . addRule ( '.animate-me' , '-webkit-transition:1s linear all;' +
1326
+
1327
+ ss . addRule ( '.animate-me div' , '-webkit-transition:1s linear all;' +
1319
1328
'transition:1s linear all;' ) ;
1329
+
1330
+ ss . addRule ( '.animate-me-longer div' , '-webkit-transition:1.5s linear all;' +
1331
+ 'transition:1.5s linear all;' ) ;
1332
+
1333
+ element = $compile ( html ( '<div class="animate-me-longer"><div ng-repeat="item in items"></div></div>' ) ) ( $rootScope ) ;
1334
+ $rootScope . items = [ 0 ] ;
1335
+ $rootScope . $digest ( ) ;
1336
+ $animate . triggerReflow ( ) ;
1337
+
1338
+ currentTimestamp += 2250 ; //1.5 * 1500 = 2250
1320
1339
1321
- element = $compile ( html ( '<div><div class=" animate-me" ng-repeat="item in items"></div></div>' ) ) ( $rootScope ) ;
1340
+ element [ 0 ] . className = ' animate-me' ;
1322
1341
1323
1342
$rootScope . items = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ;
1324
1343
var totalOperations = $rootScope . items . length ;
@@ -1327,9 +1346,11 @@ describe("ngAnimate", function() {
1327
1346
1328
1347
$rootScope . items = [ 0 ] ;
1329
1348
$animate . triggerReflow ( ) ;
1349
+
1350
+ currentTimestamp += 1500 ; //1.5 * 1000 = 1500
1330
1351
$timeout . flush ( 1500 ) ;
1331
1352
1332
- expect ( cancellations ) . toBeLessThan ( totalOperations ) ;
1353
+ expect ( cancellations ) . toBe ( 1 ) ;
1333
1354
expect ( element . children ( ) . length ) . toBe ( 10 ) ;
1334
1355
cancellations = 0 ;
1335
1356
@@ -1339,7 +1360,9 @@ describe("ngAnimate", function() {
1339
1360
$animate . triggerReflow ( ) ;
1340
1361
$timeout . flush ( 1500 ) ;
1341
1362
expect ( element . children ( ) . length ) . toBe ( 1 ) ;
1342
- expect ( cancellations ) . toBeLessThan ( totalOperations ) ;
1363
+ expect ( cancellations ) . toBe ( 1 ) ;
1364
+
1365
+ Date . now = _now ;
1343
1366
} ) ;
1344
1367
} ) ;
1345
1368
0 commit comments