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