@@ -1390,24 +1390,43 @@ describe("ngAnimate", function() {
1390
1390
} ) ) ;
1391
1391
1392
1392
it ( "should intelligently cancel former timeouts and close off a series of elements a final timeout" , function ( ) {
1393
+ var currentTimestamp = Date . now ( ) ;
1394
+ spyOn ( Date , 'now' ) . andCallFake ( function ( ) {
1395
+ return currentTimestamp ;
1396
+ } ) ;
1397
+
1393
1398
var cancellations = 0 ;
1394
1399
module ( function ( $provide ) {
1395
1400
$provide . decorator ( '$timeout' , function ( $delegate ) {
1396
1401
var _cancel = $delegate . cancel ;
1397
- $delegate . cancel = function ( ) {
1398
- cancellations ++ ;
1399
- return _cancel . apply ( $delegate , arguments ) ;
1402
+ $delegate . cancel = function ( timer ) {
1403
+ if ( timer ) {
1404
+ cancellations ++ ;
1405
+ return _cancel . apply ( $delegate , arguments ) ;
1406
+ }
1400
1407
} ;
1401
1408
return $delegate ;
1402
1409
} ) ;
1403
1410
} )
1404
1411
inject ( function ( $animate , $rootScope , $compile , $sniffer , $timeout ) {
1405
1412
if ( ! $sniffer . transitions ) return ;
1406
1413
1407
- ss . addRule ( '.animate-me' , '-webkit-transition:1s linear all;' +
1414
+ ss . addRule ( '.animate-me div ' , '-webkit-transition:1s linear all;' +
1408
1415
'transition:1s linear all;' ) ;
1409
1416
1410
- element = $compile ( html ( '<div><div class="animate-me" ng-repeat="item in items"></div></div>' ) ) ( $rootScope ) ;
1417
+ ss . addRule ( '.animate-me-longer div' , '-webkit-transition:1.5s linear all;' +
1418
+ 'transition:1.5s linear all;' ) ;
1419
+
1420
+ element = $compile ( html ( '<div class="animate-me-longer">' +
1421
+ ' <div ng-repeat="item in items"></div>' +
1422
+ '</div>' ) ) ( $rootScope ) ;
1423
+ $rootScope . items = [ 0 ] ;
1424
+ $rootScope . $digest ( ) ;
1425
+ $animate . triggerReflow ( ) ;
1426
+
1427
+ currentTimestamp += 2250 ; //1.5 * 1500 = 2250
1428
+
1429
+ element [ 0 ] . className = 'animate-me' ;
1411
1430
1412
1431
$rootScope . items = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ;
1413
1432
var totalOperations = $rootScope . items . length ;
@@ -1416,9 +1435,11 @@ describe("ngAnimate", function() {
1416
1435
1417
1436
$rootScope . items = [ 0 ] ;
1418
1437
$animate . triggerReflow ( ) ;
1438
+
1439
+ currentTimestamp += 1500 ; //1.5 * 1000 = 1500
1419
1440
$timeout . flush ( 1500 ) ;
1420
1441
1421
- expect ( cancellations ) . toBeLessThan ( totalOperations ) ;
1442
+ expect ( cancellations ) . toBe ( 1 ) ;
1422
1443
expect ( element . children ( ) . length ) . toBe ( 10 ) ;
1423
1444
cancellations = 0 ;
1424
1445
@@ -1428,7 +1449,7 @@ describe("ngAnimate", function() {
1428
1449
$animate . triggerReflow ( ) ;
1429
1450
$timeout . flush ( 1500 ) ;
1430
1451
expect ( element . children ( ) . length ) . toBe ( 1 ) ;
1431
- expect ( cancellations ) . toBeLessThan ( totalOperations ) ;
1452
+ expect ( cancellations ) . toBe ( 1 ) ;
1432
1453
} ) ;
1433
1454
} ) ;
1434
1455
0 commit comments