@@ -1332,24 +1332,43 @@ describe("ngAnimate", function() {
1332
1332
} ) ) ;
1333
1333
1334
1334
it ( "should intelligently cancel former timeouts and close off a series of elements a final timeout" , function ( ) {
1335
+ var currentTimestamp = Date . now ( ) ;
1336
+ spyOn ( Date , 'now' ) . andCallFake ( function ( ) {
1337
+ return currentTimestamp ;
1338
+ } ) ;
1339
+
1335
1340
var cancellations = 0 ;
1336
1341
module ( function ( $provide ) {
1337
1342
$provide . decorator ( '$timeout' , function ( $delegate ) {
1338
1343
var _cancel = $delegate . cancel ;
1339
- $delegate . cancel = function ( ) {
1340
- cancellations ++ ;
1341
- return _cancel . apply ( $delegate , arguments ) ;
1344
+ $delegate . cancel = function ( timer ) {
1345
+ if ( timer ) {
1346
+ cancellations ++ ;
1347
+ return _cancel . apply ( $delegate , arguments ) ;
1348
+ }
1342
1349
} ;
1343
1350
return $delegate ;
1344
1351
} ) ;
1345
1352
} )
1346
1353
inject ( function ( $animate , $rootScope , $compile , $sniffer , $timeout ) {
1347
1354
if ( ! $sniffer . transitions ) return ;
1348
1355
1349
- ss . addRule ( '.animate-me' , '-webkit-transition:1s linear all;' +
1356
+ ss . addRule ( '.animate-me div ' , '-webkit-transition:1s linear all;' +
1350
1357
'transition:1s linear all;' ) ;
1351
1358
1352
- element = $compile ( html ( '<div><div class="animate-me" ng-repeat="item in items"></div></div>' ) ) ( $rootScope ) ;
1359
+ ss . addRule ( '.animate-me-longer div' , '-webkit-transition:1.5s linear all;' +
1360
+ 'transition:1.5s linear all;' ) ;
1361
+
1362
+ element = $compile ( html ( '<div class="animate-me-longer">' +
1363
+ ' <div ng-repeat="item in items"></div>' +
1364
+ '</div>' ) ) ( $rootScope ) ;
1365
+ $rootScope . items = [ 0 ] ;
1366
+ $rootScope . $digest ( ) ;
1367
+ $animate . triggerReflow ( ) ;
1368
+
1369
+ currentTimestamp += 2250 ; //1.5 * 1500 = 2250
1370
+
1371
+ element [ 0 ] . className = 'animate-me' ;
1353
1372
1354
1373
$rootScope . items = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ;
1355
1374
var totalOperations = $rootScope . items . length ;
@@ -1358,9 +1377,11 @@ describe("ngAnimate", function() {
1358
1377
1359
1378
$rootScope . items = [ 0 ] ;
1360
1379
$animate . triggerReflow ( ) ;
1380
+
1381
+ currentTimestamp += 1500 ; //1.5 * 1000 = 1500
1361
1382
$timeout . flush ( 1500 ) ;
1362
1383
1363
- expect ( cancellations ) . toBeLessThan ( totalOperations ) ;
1384
+ expect ( cancellations ) . toBe ( 1 ) ;
1364
1385
expect ( element . children ( ) . length ) . toBe ( 10 ) ;
1365
1386
cancellations = 0 ;
1366
1387
@@ -1370,7 +1391,7 @@ describe("ngAnimate", function() {
1370
1391
$animate . triggerReflow ( ) ;
1371
1392
$timeout . flush ( 1500 ) ;
1372
1393
expect ( element . children ( ) . length ) . toBe ( 1 ) ;
1373
- expect ( cancellations ) . toBeLessThan ( totalOperations ) ;
1394
+ expect ( cancellations ) . toBe ( 1 ) ;
1374
1395
} ) ;
1375
1396
} ) ;
1376
1397
0 commit comments