Skip to content

Commit dc48aad

Browse files
committedAug 19, 2015
fix(ngAnimate): only buffer rAF requests within the animation runners
Closes angular#12280
1 parent ebce2f7 commit dc48aad

16 files changed

+269
-220
lines changed
 

‎src/ngAnimate/animateJs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// by the time...
66

77
var $$AnimateJsProvider = ['$animateProvider', function($animateProvider) {
8-
this.$get = ['$injector', '$$AnimateRunner', '$$rAFMutex', '$$jqLite',
9-
function($injector, $$AnimateRunner, $$rAFMutex, $$jqLite) {
8+
this.$get = ['$injector', '$$AnimateRunner', '$$jqLite',
9+
function($injector, $$AnimateRunner, $$jqLite) {
1010

1111
var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);
1212
// $animateJs(element, 'enter');

‎src/ngAnimate/animateRunner.js

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
'use strict';
22

3-
var $$rAFMutexFactory = ['$$rAF', function($$rAF) {
3+
var $$AnimateAsyncRunFactory = ['$$rAF', function($$rAF) {
4+
var waitQueue = [];
5+
6+
function waitForTick(fn) {
7+
waitQueue.push(fn);
8+
if (waitQueue.length > 1) return;
9+
$$rAF(function() {
10+
for (var i = 0; i < waitQueue.length; i++) {
11+
waitQueue[i]();
12+
}
13+
waitQueue = [];
14+
});
15+
}
16+
417
return function() {
518
var passed = false;
6-
$$rAF(function() {
19+
waitForTick(function() {
720
passed = true;
821
});
9-
return function(fn) {
10-
passed ? fn() : $$rAF(fn);
22+
return function(callback) {
23+
passed ? callback() : waitForTick(callback);
1124
};
1225
};
1326
}];
1427

15-
var $$AnimateRunnerFactory = ['$q', '$$rAFMutex', function($q, $$rAFMutex) {
28+
var $$AnimateRunnerFactory = ['$q', '$sniffer', '$$animateAsyncRun',
29+
function($q, $sniffer, $$animateAsyncRun) {
30+
1631
var INITIAL_STATE = 0;
1732
var DONE_PENDING_STATE = 1;
1833
var DONE_COMPLETE_STATE = 2;
@@ -57,7 +72,7 @@ var $$AnimateRunnerFactory = ['$q', '$$rAFMutex', function($q, $$rAFMutex) {
5772
this.setHost(host);
5873

5974
this._doneCallbacks = [];
60-
this._runInAnimationFrame = $$rAFMutex();
75+
this._runInAnimationFrame = $$animateAsyncRun();
6176
this._state = 0;
6277
}
6378

‎src/ngAnimate/module.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* global angularAnimateModule: true,
44
55
$$BodyProvider,
6-
$$rAFMutexFactory,
6+
$$AnimateAsyncRunFactory,
77
$$AnimateChildrenDirective,
88
$$AnimateRunnerFactory,
99
$$AnimateQueueProvider,
@@ -745,9 +745,8 @@ angular.module('ngAnimate', [])
745745

746746
.directive('ngAnimateChildren', $$AnimateChildrenDirective)
747747

748-
.factory('$$rAFMutex', $$rAFMutexFactory)
749-
750748
.factory('$$AnimateRunner', $$AnimateRunnerFactory)
749+
.factory('$$animateAsyncRun', $$AnimateAsyncRunFactory)
751750

752751
.provider('$$animateQueue', $$AnimateQueueProvider)
753752
.provider('$$animation', $$AnimationProvider)

‎src/ngMock/angular-mocks.js

+44-19
Original file line numberDiff line numberDiff line change
@@ -763,25 +763,50 @@ angular.mock.animate = angular.module('ngAnimateMock', ['ng'])
763763
return reflowFn;
764764
});
765765

766-
$provide.decorator('$animate', ['$delegate', '$timeout', '$browser', '$$rAF', '$$forceReflow',
767-
function($delegate, $timeout, $browser, $$rAF, $$forceReflow) {
766+
$provide.factory('$$animateAsyncRun', function() {
767+
var queue = [];
768+
var queueFn = function() {
769+
return function(fn) {
770+
queue.push(fn);
771+
};
772+
};
773+
queueFn.flush = function() {
774+
if (queue.length === 0) return false;
775+
776+
for (var i = 0; i < queue.length; i++) {
777+
queue[i]();
778+
}
779+
queue = [];
780+
781+
return true;
782+
};
783+
return queueFn;
784+
});
785+
786+
$provide.decorator('$animate', ['$delegate', '$timeout', '$browser', '$$rAF', '$$forceReflow', '$$animateAsyncRun',
787+
function($delegate, $timeout, $browser, $$rAF, $$forceReflow, $$animateAsyncRun) {
768788

769789
var animate = {
770790
queue: [],
771791
cancel: $delegate.cancel,
792+
on: $delegate.on,
793+
off: $delegate.off,
794+
pin: $delegate.pin,
772795
get reflows() {
773796
return $$forceReflow.totalReflows;
774797
},
775798
enabled: $delegate.enabled,
776-
triggerCallbackEvents: function() {
777-
$$rAF.flush();
778-
},
779-
triggerCallbackPromise: function() {
780-
$timeout.flush(0);
781-
},
782-
triggerCallbacks: function() {
783-
this.triggerCallbackEvents();
784-
this.triggerCallbackPromise();
799+
flush: function() {
800+
var rafsFlushed = false;
801+
if ($$rAF.queue.length) {
802+
$$rAF.flush();
803+
rafsFlushed = true;
804+
}
805+
806+
var animatorsFlushed = $$animateAsyncRun.flush();
807+
if (!rafsFlushed && !animatorsFlushed) {
808+
throw new Error('No pending animations ready to be closed or flushed');
809+
}
785810
}
786811
};
787812

@@ -1733,28 +1758,28 @@ angular.mock.$TimeoutDecorator = ['$delegate', '$browser', function($delegate, $
17331758
}];
17341759

17351760
angular.mock.$RAFDecorator = ['$delegate', function($delegate) {
1736-
var queue = [];
17371761
var rafFn = function(fn) {
1738-
var index = queue.length;
1739-
queue.push(fn);
1762+
var index = rafFn.queue.length;
1763+
rafFn.queue.push(fn);
17401764
return function() {
1741-
queue.splice(index, 1);
1765+
rafFn.queue.splice(index, 1);
17421766
};
17431767
};
17441768

1769+
rafFn.queue = [];
17451770
rafFn.supported = $delegate.supported;
17461771

17471772
rafFn.flush = function() {
1748-
if (queue.length === 0) {
1773+
if (rafFn.queue.length === 0) {
17491774
throw new Error('No rAF callbacks present');
17501775
}
17511776

1752-
var length = queue.length;
1777+
var length = rafFn.queue.length;
17531778
for (var i = 0; i < length; i++) {
1754-
queue[i]();
1779+
rafFn.queue[i]();
17551780
}
17561781

1757-
queue = queue.slice(i);
1782+
rafFn.queue = rafFn.queue.slice(i);
17581783
};
17591784

17601785
return rafFn;

‎test/ng/directive/ngClassSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ describe('ngClass animations', function() {
468468
};
469469
});
470470
});
471-
inject(function($compile, $rootScope, $browser, $rootElement, $animate, $timeout, $$body, $$rAF) {
471+
inject(function($compile, $rootScope, $browser, $rootElement, $animate, $timeout, $$body) {
472472
$animate.enabled(true);
473473

474474
$rootScope.val = 'crazy';
@@ -488,7 +488,7 @@ describe('ngClass animations', function() {
488488
expect(enterComplete).toBe(false);
489489

490490
$rootScope.$digest();
491-
$$rAF.flush();
491+
$animate.flush();
492492
$rootScope.$digest();
493493

494494
expect(element.hasClass('crazy')).toBe(true);

‎test/ng/directive/ngIncludeSpec.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,11 @@ describe('ngInclude', function() {
428428
});
429429

430430
expect(autoScrollSpy).not.toHaveBeenCalled();
431-
expect($animate.queue.shift().event).toBe('enter');
432-
$animate.triggerCallbacks();
433431

432+
$animate.flush();
433+
$rootScope.$digest();
434+
435+
expect($animate.queue.shift().event).toBe('enter');
434436
expect(autoScrollSpy).toHaveBeenCalledOnce();
435437
}));
436438

@@ -446,7 +448,6 @@ describe('ngInclude', function() {
446448
});
447449

448450
expect($animate.queue.shift().event).toBe('enter');
449-
$animate.triggerCallbacks();
450451

451452
$rootScope.$apply(function() {
452453
$rootScope.tpl = 'another.html';
@@ -455,7 +456,6 @@ describe('ngInclude', function() {
455456

456457
expect($animate.queue.shift().event).toBe('leave');
457458
expect($animate.queue.shift().event).toBe('enter');
458-
$animate.triggerCallbacks();
459459

460460
$rootScope.$apply(function() {
461461
$rootScope.tpl = 'template.html';
@@ -464,7 +464,9 @@ describe('ngInclude', function() {
464464

465465
expect($animate.queue.shift().event).toBe('leave');
466466
expect($animate.queue.shift().event).toBe('enter');
467-
$animate.triggerCallbacks();
467+
468+
$animate.flush();
469+
$rootScope.$digest();
468470

469471
expect(autoScrollSpy).toHaveBeenCalled();
470472
expect(autoScrollSpy.callCount).toBe(3);
@@ -480,7 +482,6 @@ describe('ngInclude', function() {
480482
});
481483

482484
expect($animate.queue.shift().event).toBe('enter');
483-
$animate.triggerCallbacks();
484485
expect(autoScrollSpy).not.toHaveBeenCalled();
485486
}));
486487

@@ -496,7 +497,6 @@ describe('ngInclude', function() {
496497
});
497498

498499
expect($animate.queue.shift().event).toBe('enter');
499-
$animate.triggerCallbacks();
500500

501501
$rootScope.$apply(function() {
502502
$rootScope.tpl = 'template.html';
@@ -518,7 +518,9 @@ describe('ngInclude', function() {
518518

519519
$rootScope.$apply("tpl = 'template.html'");
520520
expect($animate.queue.shift().event).toBe('enter');
521-
$animate.triggerCallbacks();
521+
522+
$animate.flush();
523+
$rootScope.$digest();
522524

523525
expect(autoScrollSpy).toHaveBeenCalledOnce();
524526
}

‎test/ng/directive/ngRepeatSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ describe('ngRepeat animations', function() {
14621462
}));
14631463

14641464
it('should not change the position of the block that is being animated away via a leave animation',
1465-
inject(function($compile, $rootScope, $animate, $document, $window, $sniffer, $timeout, $$rAF) {
1465+
inject(function($compile, $rootScope, $animate, $document, $window, $sniffer, $timeout) {
14661466
if (!$sniffer.transitions) return;
14671467

14681468
var item;
@@ -1487,7 +1487,7 @@ describe('ngRepeat animations', function() {
14871487
$rootScope.$digest();
14881488

14891489
expect(element.text()).toBe('123'); // the original order should be preserved
1490-
$$rAF.flush();
1490+
$animate.flush();
14911491
$timeout.flush(1500); // 1s * 1.5 closing buffer
14921492
expect(element.text()).toBe('13');
14931493
} finally {

‎test/ngAnimate/animateCssDriverSpec.js

+19-27
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
describe("ngAnimate $$animateCssDriver", function() {
44

55
beforeEach(module('ngAnimate'));
6+
beforeEach(module('ngAnimateMock'));
67

78
function int(x) {
89
return parseInt(x, 10);
@@ -414,7 +415,7 @@ describe("ngAnimate $$animateCssDriver", function() {
414415
}));
415416

416417
it("should then do an addClass('ng-anchor-in') animation on the cloned anchor and remove the old class",
417-
inject(function($rootElement, $$rAF) {
418+
inject(function($rootElement) {
418419

419420
var fromAnchor = jqLite('<div></div>');
420421
from.append(fromAnchor);
@@ -434,7 +435,6 @@ describe("ngAnimate $$animateCssDriver", function() {
434435
}).start();
435436

436437
captureLog.pop().runner.end();
437-
$$rAF.flush();
438438

439439
var anchorDetails = captureLog.pop().args[1];
440440
expect(anchorDetails.removeClass.trim()).toBe('ng-anchor-out');
@@ -464,7 +464,7 @@ describe("ngAnimate $$animateCssDriver", function() {
464464
});
465465
});
466466

467-
inject(function($rootElement, $$rAF) {
467+
inject(function($rootElement, $animate) {
468468
var fromAnchor = jqLite('<div></div>');
469469
from.append(fromAnchor);
470470
var toAnchor = jqLite('<div></div>');
@@ -488,7 +488,7 @@ describe("ngAnimate $$animateCssDriver", function() {
488488

489489
expect(animationStarted).toBe(expectedClass);
490490
runner.end();
491-
$$rAF.flush();
491+
$animate.flush();
492492
expect(complete).toBe(true);
493493
});
494494
});
@@ -552,7 +552,7 @@ describe("ngAnimate $$animateCssDriver", function() {
552552
expect(int(fromStyles.left)).toBeGreaterThan(149);
553553
}));
554554

555-
it("should append a `px` value for all seeded animation styles", inject(function($rootElement, $$rAF) {
555+
it("should append a `px` value for all seeded animation styles", inject(function($rootElement) {
556556
ss.addRule('.starting-element', 'width:10px; height:20px; display:inline-block;');
557557

558558
var fromAnchor = jqLite('<div class="starting-element"' +
@@ -582,7 +582,6 @@ describe("ngAnimate $$animateCssDriver", function() {
582582

583583
// the out animation goes first
584584
anchorAnimation.runner.end();
585-
$$rAF.flush();
586585

587586
anchorAnimation = captureLog.pop();
588587
anchorDetails = anchorAnimation.args[1];
@@ -593,7 +592,7 @@ describe("ngAnimate $$animateCssDriver", function() {
593592
}));
594593

595594
it("should then do an removeClass('out') + addClass('in') animation on the cloned anchor",
596-
inject(function($rootElement, $$rAF) {
595+
inject(function($rootElement) {
597596

598597
var fromAnchor = jqLite('<div></div>');
599598
from.append(fromAnchor);
@@ -614,7 +613,6 @@ describe("ngAnimate $$animateCssDriver", function() {
614613

615614
// the out animation goes first
616615
captureLog.pop().runner.end();
617-
$$rAF.flush();
618616

619617
var anchorDetails = captureLog.pop().args[1];
620618
expect(anchorDetails.removeClass).toMatch(/\bout\b/);
@@ -623,7 +621,7 @@ describe("ngAnimate $$animateCssDriver", function() {
623621
}));
624622

625623
it("should add the `ng-anchor` class to the cloned anchor element",
626-
inject(function($rootElement, $$rAF) {
624+
inject(function($rootElement) {
627625

628626
var fromAnchor = jqLite('<div></div>');
629627
from.append(fromAnchor);
@@ -647,7 +645,7 @@ describe("ngAnimate $$animateCssDriver", function() {
647645
}));
648646

649647
it("should add and remove the `ng-animate-shim` class on the in anchor element during the animation",
650-
inject(function($rootElement, $$rAF) {
648+
inject(function($rootElement) {
651649

652650
var fromAnchor = jqLite('<div></div>');
653651
from.append(fromAnchor);
@@ -670,14 +668,13 @@ describe("ngAnimate $$animateCssDriver", function() {
670668

671669
// the out animation goes first
672670
captureLog.pop().runner.end();
673-
$$rAF.flush();
674671
captureLog.pop().runner.end();
675672

676673
expect(fromAnchor).not.toHaveClass('ng-animate-shim');
677674
}));
678675

679676
it("should add and remove the `ng-animate-shim` class on the out anchor element during the animation",
680-
inject(function($rootElement, $$rAF) {
677+
inject(function($rootElement) {
681678

682679
var fromAnchor = jqLite('<div></div>');
683680
from.append(fromAnchor);
@@ -700,7 +697,6 @@ describe("ngAnimate $$animateCssDriver", function() {
700697

701698
// the out animation goes first
702699
captureLog.pop().runner.end();
703-
$$rAF.flush();
704700

705701
expect(toAnchor).toHaveClass('ng-animate-shim');
706702
captureLog.pop().runner.end();
@@ -709,7 +705,7 @@ describe("ngAnimate $$animateCssDriver", function() {
709705
}));
710706

711707
it("should create the cloned anchor with all of the classes from the from anchor element",
712-
inject(function($rootElement, $$rAF) {
708+
inject(function($rootElement) {
713709

714710
var fromAnchor = jqLite('<div class="yes no maybe"></div>');
715711
from.append(fromAnchor);
@@ -733,7 +729,7 @@ describe("ngAnimate $$animateCssDriver", function() {
733729
}));
734730

735731
it("should remove the classes of the starting anchor from the cloned anchor node during the in animation and also add the classes of the destination anchor within the same animation",
736-
inject(function($rootElement, $$rAF) {
732+
inject(function($rootElement) {
737733

738734
var fromAnchor = jqLite('<div class="yes no maybe"></div>');
739735
from.append(fromAnchor);
@@ -754,7 +750,6 @@ describe("ngAnimate $$animateCssDriver", function() {
754750

755751
// the out animation goes first
756752
captureLog.pop().runner.end();
757-
$$rAF.flush();
758753

759754
var anchorDetails = captureLog.pop().args[1];
760755
var removedClasses = anchorDetails.removeClass.split(' ');
@@ -765,7 +760,7 @@ describe("ngAnimate $$animateCssDriver", function() {
765760
}));
766761

767762
it("should not attempt to add/remove any classes that contain a `ng-` prefix",
768-
inject(function($rootElement, $$rAF) {
763+
inject(function($rootElement) {
769764

770765
var fromAnchor = jqLite('<div class="ng-yes ng-no sure"></div>');
771766
from.append(fromAnchor);
@@ -786,7 +781,6 @@ describe("ngAnimate $$animateCssDriver", function() {
786781

787782
// the out animation goes first
788783
captureLog.pop().runner.end();
789-
$$rAF.flush();
790784

791785
var inAnimation = captureLog.pop();
792786
var details = inAnimation.args[1];
@@ -802,7 +796,7 @@ describe("ngAnimate $$animateCssDriver", function() {
802796
}));
803797

804798
it("should not remove any shared CSS classes between the starting and destination anchor element during the in animation",
805-
inject(function($rootElement, $$rAF) {
799+
inject(function($rootElement) {
806800

807801
var fromAnchor = jqLite('<div class="blue green red"></div>');
808802
from.append(fromAnchor);
@@ -823,7 +817,6 @@ describe("ngAnimate $$animateCssDriver", function() {
823817

824818
// the out animation goes first
825819
captureLog.pop().runner.end();
826-
$$rAF.flush();
827820

828821
var inAnimation = captureLog.pop();
829822
var clonedAnchor = inAnimation.element;
@@ -851,7 +844,7 @@ describe("ngAnimate $$animateCssDriver", function() {
851844
}));
852845

853846
it("should continue the anchor animation by seeding the to styles based on where the final anchor element will be positioned",
854-
inject(function($rootElement, $$rAF) {
847+
inject(function($rootElement) {
855848
ss.addRule('.ending-element', 'width:9999px; height:6666px; display:inline-block;');
856849

857850
var fromAnchor = jqLite('<div></div>');
@@ -874,7 +867,6 @@ describe("ngAnimate $$animateCssDriver", function() {
874867
}).start();
875868

876869
captureLog.pop().runner.end();
877-
$$rAF.flush();
878870

879871
var anchorAnimation = captureLog.pop();
880872
var anchorElement = anchorAnimation.element;
@@ -889,7 +881,7 @@ describe("ngAnimate $$animateCssDriver", function() {
889881
}));
890882

891883
it("should remove the cloned anchor node from the DOM once the 'in' animation is complete",
892-
inject(function($rootElement, $$rAF) {
884+
inject(function($rootElement) {
893885

894886
var fromAnchor = jqLite('<div class="blue green red"></div>');
895887
from.append(fromAnchor);
@@ -913,7 +905,6 @@ describe("ngAnimate $$animateCssDriver", function() {
913905
var clonedAnchor = inAnimation.element;
914906
expect(clonedAnchor.parent().length).toBe(1);
915907
inAnimation.runner.end();
916-
$$rAF.flush();
917908

918909
// now the in animation completes
919910
expect(clonedAnchor.parent().length).toBe(1);
@@ -923,7 +914,7 @@ describe("ngAnimate $$animateCssDriver", function() {
923914
}));
924915

925916
it("should pass the provided domOperation into $animateCss to be run right after the element is animated if a leave animation is present",
926-
inject(function($rootElement, $$rAF) {
917+
inject(function($rootElement) {
927918

928919
toAnimation.structural = true;
929920
toAnimation.event = 'enter';
@@ -949,7 +940,7 @@ describe("ngAnimate $$animateCssDriver", function() {
949940
}));
950941

951942
it("should fire the returned runner promise when the from, to and anchor animations are all complete",
952-
inject(function($rootElement, $rootScope, $$rAF) {
943+
inject(function($rootElement, $rootScope, $animate) {
953944

954945
ss.addRule('.ending-element', 'width:9999px; height:6666px; display:inline-block;');
955946

@@ -978,7 +969,8 @@ describe("ngAnimate $$animateCssDriver", function() {
978969
captureLog.pop().runner.end(); //to
979970
captureLog.pop().runner.end(); //anchor(out)
980971
captureLog.pop().runner.end(); //anchor(in)
981-
$$rAF.flush();
972+
973+
$animate.flush();
982974
$rootScope.$digest();
983975

984976
expect(completed).toBe(true);

‎test/ngAnimate/animateCssSpec.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
describe("ngAnimate $animateCss", function() {
44

55
beforeEach(module('ngAnimate'));
6+
beforeEach(module('ngAnimateMock'));
67

78
function assertAnimationRunning(element, not) {
89
var className = element.attr('class');
@@ -52,7 +53,7 @@ describe("ngAnimate $animateCss", function() {
5253
if (!browserSupportsCssAnimations()) return;
5354

5455
it("should silently quit the animation and not throw when an element has no parent during preparation",
55-
inject(function($animateCss, $$rAF, $rootScope, $document, $rootElement) {
56+
inject(function($animateCss, $rootScope, $document, $rootElement) {
5657

5758
var element = jqLite('<div></div>');
5859
expect(function() {
@@ -385,7 +386,7 @@ describe("ngAnimate $animateCss", function() {
385386
they("should close the animation, but still accept $prop callbacks if no animation is detected",
386387
['done', 'then'], function(method) {
387388

388-
inject(function($animateCss, $$rAF, $rootScope) {
389+
inject(function($animateCss, $animate, $rootScope) {
389390
ss.addRule('.the-third-fake-animation', 'background:green;');
390391

391392
element.addClass('another-fake-animation');
@@ -400,7 +401,8 @@ describe("ngAnimate $animateCss", function() {
400401
});
401402

402403
expect(done).toBe(false);
403-
$$rAF.flush();
404+
$animate.flush();
405+
404406
if (method === 'then') {
405407
$rootScope.$digest();
406408
}
@@ -411,7 +413,7 @@ describe("ngAnimate $animateCss", function() {
411413
they("should close the animation, but still accept recognize runner.$prop if no animation is detected",
412414
['done(cancel)', 'catch'], function(method) {
413415

414-
inject(function($animateCss, $$rAF, $rootScope) {
416+
inject(function($animateCss, $rootScope) {
415417
ss.addRule('.the-third-fake-animation', 'background:green;');
416418

417419
element.addClass('another-fake-animation');
@@ -1078,7 +1080,7 @@ describe("ngAnimate $animateCss", function() {
10781080
}));
10791081

10801082
it("should still resolve the animation once expired",
1081-
inject(function($animateCss, $$body, $rootElement, $timeout) {
1083+
inject(function($animateCss, $$body, $rootElement, $timeout, $animate, $rootScope) {
10821084

10831085
ss.addRule('.ng-enter', 'transition:10s linear all;');
10841086

@@ -1097,11 +1099,13 @@ describe("ngAnimate $animateCss", function() {
10971099

10981100
triggerAnimationStartFrame();
10991101
$timeout.flush(15000);
1102+
$animate.flush();
1103+
$rootScope.$digest();
11001104
expect(passed).toBe(true);
11011105
}));
11021106

11031107
it("should not resolve/reject after passing if the animation completed successfully",
1104-
inject(function($animateCss, $$body, $rootElement, $timeout, $rootScope) {
1108+
inject(function($animateCss, $$body, $rootElement, $timeout, $rootScope, $animate) {
11051109

11061110
ss.addRule('.ng-enter', 'transition:10s linear all;');
11071111

@@ -1125,6 +1129,7 @@ describe("ngAnimate $animateCss", function() {
11251129
browserTrigger(element, 'transitionend',
11261130
{ timeStamp: Date.now() + 1000, elapsedTime: 10 });
11271131

1132+
$animate.flush();
11281133
$rootScope.$digest();
11291134

11301135
expect(passed).toBe(true);
@@ -1137,7 +1142,7 @@ describe("ngAnimate $animateCss", function() {
11371142
}));
11381143

11391144
it("should close all stacked animations after the last timeout runs on the same element",
1140-
inject(function($animateCss, $$body, $rootElement, $timeout) {
1145+
inject(function($animateCss, $$body, $rootElement, $timeout, $animate) {
11411146

11421147
var now = 0;
11431148
spyOn(Date, 'now').andCallFake(function() {
@@ -1176,6 +1181,8 @@ describe("ngAnimate $animateCss", function() {
11761181

11771182
// this will close the animations fully
11781183
fastForwardClock(3500);
1184+
$animate.flush();
1185+
11791186
expect(doneSpy).toHaveBeenCalled();
11801187
expect(doneSpy.callCount).toBe(3);
11811188

@@ -1218,7 +1225,7 @@ describe("ngAnimate $animateCss", function() {
12181225
}));
12191226

12201227
it("should cache frequent calls to getComputedStyle before the next animation frame kicks in",
1221-
inject(function($animateCss, $document, $rootElement, $$rAF) {
1228+
inject(function($animateCss, $document, $rootElement) {
12221229

12231230
var i, elm, animator;
12241231
for (i = 0; i < 5; i++) {

‎test/ngAnimate/animateJsDriverSpec.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
describe("ngAnimate $$animateJsDriver", function() {
44

55
beforeEach(module('ngAnimate'));
6+
beforeEach(module('ngAnimateMock'));
67

78
it('should register the $$animateJsDriver into the list of drivers found in $animateProvider',
89
module(function($animateProvider) {
@@ -96,7 +97,7 @@ describe("ngAnimate $$animateJsDriver", function() {
9697
}));
9798

9899
they('should $prop both animations when $prop() is called on the runner', ['end', 'cancel'], function(method) {
99-
inject(function($rootScope, $$rAF) {
100+
inject(function($rootScope, $animate) {
100101
var child1 = jqLite('<div></div>');
101102
element.append(child1);
102103
var child2 = jqLite('<div></div>');
@@ -127,15 +128,15 @@ describe("ngAnimate $$animateJsDriver", function() {
127128
$rootScope.$digest();
128129

129130
runner[method]();
130-
$$rAF.flush();
131+
$animate.flush();
131132

132133
expect(animationsClosed).toBe(true);
133134
expect(status).toBe(method === 'end' ? true : false);
134135
});
135136
});
136137

137138
they('should fully $prop when all inner animations are complete', ['end', 'cancel'], function(method) {
138-
inject(function($rootScope, $$rAF) {
139+
inject(function($rootScope, $animate) {
139140
var child1 = jqLite('<div></div>');
140141
element.append(child1);
141142
var child2 = jqLite('<div></div>');
@@ -163,12 +164,12 @@ describe("ngAnimate $$animateJsDriver", function() {
163164
status = s;
164165
});
165166

166-
$$rAF.flush();
167-
168167
captureLog[0].runner[method]();
169168
expect(animationsClosed).toBe(false);
170169

171170
captureLog[1].runner[method]();
171+
$animate.flush();
172+
172173
expect(animationsClosed).toBe(true);
173174

174175
expect(status).toBe(method === 'end' ? true : false);

‎test/ngAnimate/animateJsSpec.js

+35-34
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
describe("ngAnimate $$animateJs", function() {
44

55
beforeEach(module('ngAnimate'));
6+
beforeEach(module('ngAnimateMock'));
67

78
function getDoneFunction(args) {
89
for (var i = 1; i < args.length; i++) {
@@ -86,7 +87,7 @@ describe("ngAnimate $$animateJs", function() {
8687
$animateProvider.register('.two', makeAnimation('enter'));
8788
$animateProvider.register('.three', makeAnimation('enter'));
8889
});
89-
inject(function($$animateJs, $$rAF) {
90+
inject(function($$animateJs, $animate) {
9091
var element = jqLite('<div class="one two three"></div>');
9192
var animator = $$animateJs(element, 'enter');
9293
var complete = false;
@@ -97,7 +98,7 @@ describe("ngAnimate $$animateJs", function() {
9798
forEach(doneCallbacks, function(cb) {
9899
cb();
99100
});
100-
$$rAF.flush();
101+
$animate.flush();
101102
expect(complete).toBe(true);
102103
});
103104
});
@@ -206,7 +207,7 @@ describe("ngAnimate $$animateJs", function() {
206207
};
207208
});
208209
});
209-
inject(function($$animateJs, $$rAF) {
210+
inject(function($$animateJs, $animate) {
210211
var element = jqLite('<div class="the-end"></div>');
211212
var animator = $$animateJs(element, 'addClass', {
212213
addClass: 'red'
@@ -221,12 +222,12 @@ describe("ngAnimate $$animateJs", function() {
221222
before();
222223

223224
expect(after).toBeUndefined();
224-
$$rAF.flush();
225+
$animate.flush();
225226
expect(after).toBeDefined();
226227
after();
227228

228229
expect(endCalled).toBeUndefined();
229-
$$rAF.flush();
230+
$animate.flush();
230231
expect(endCalled).toBe(true);
231232
});
232233
});
@@ -251,7 +252,7 @@ describe("ngAnimate $$animateJs", function() {
251252
};
252253
});
253254
});
254-
inject(function($$animateJs, $$rAF) {
255+
inject(function($$animateJs, $animate) {
255256
var element = jqLite('<div class="the-end"></div>');
256257
var animator = $$animateJs(element, 'addClass', {
257258
domOperation: function() {
@@ -264,7 +265,7 @@ describe("ngAnimate $$animateJs", function() {
264265
});
265266
runner[method]();
266267

267-
$$rAF.flush();
268+
$animate.flush();
268269
expect(log).toEqual(
269270
['before addClass ' + method,
270271
'dom addClass',
@@ -278,7 +279,7 @@ describe("ngAnimate $$animateJs", function() {
278279
return { beforeAddClass: noop };
279280
});
280281
});
281-
inject(function($$animateJs, $$rAF, $rootScope) {
282+
inject(function($$animateJs, $animate, $rootScope) {
282283
var element = jqLite('<div class="the-end"></div>');
283284
var animator = $$animateJs(element, 'addClass');
284285
var runner = animator.start();
@@ -291,7 +292,7 @@ describe("ngAnimate $$animateJs", function() {
291292
});
292293

293294
runner.end();
294-
$$rAF.flush();
295+
$animate.flush();
295296
$rootScope.$digest();
296297
expect(done).toBe(true);
297298
expect(cancelled).toBe(false);
@@ -304,7 +305,7 @@ describe("ngAnimate $$animateJs", function() {
304305
return { beforeAddClass: noop };
305306
});
306307
});
307-
inject(function($$animateJs, $$rAF, $rootScope) {
308+
inject(function($$animateJs, $animate, $rootScope) {
308309
var element = jqLite('<div class="the-end"></div>');
309310
var animator = $$animateJs(element, 'addClass');
310311
var runner = animator.start();
@@ -317,7 +318,7 @@ describe("ngAnimate $$animateJs", function() {
317318
});
318319

319320
runner.cancel();
320-
$$rAF.flush();
321+
$animate.flush();
321322
$rootScope.$digest();
322323
expect(done).toBe(false);
323324
expect(cancelled).toBe(true);
@@ -504,7 +505,7 @@ describe("ngAnimate $$animateJs", function() {
504505
var allEvents = ['leave'].concat(otherEvents).concat(enterMoveEvents);
505506

506507
they("$prop should asynchronously render the before$prop animation", otherEvents, function(event) {
507-
inject(function($$rAF) {
508+
inject(function($animate) {
508509
var beforeMethod = 'before' + event.charAt(0).toUpperCase() + event.substr(1);
509510
animations[beforeMethod] = function(element, a, b, c) {
510511
log.push('before ' + event);
@@ -514,14 +515,14 @@ describe("ngAnimate $$animateJs", function() {
514515

515516
runAnimation(event);
516517
expect(log).toEqual(['before ' + event]);
517-
$$rAF.flush();
518+
$animate.flush();
518519

519520
expect(log).toEqual(['before ' + event, 'dom ' + event]);
520521
});
521522
});
522523

523524
they("$prop should asynchronously render the $prop animation", allEvents, function(event) {
524-
inject(function($$rAF) {
525+
inject(function($animate) {
525526
animations[event] = function(element, a, b, c) {
526527
log.push('after ' + event);
527528
var done = getDoneFunction(arguments);
@@ -534,11 +535,11 @@ describe("ngAnimate $$animateJs", function() {
534535

535536
if (event === 'leave') {
536537
expect(log).toEqual(['after leave']);
537-
$$rAF.flush();
538+
$animate.flush();
538539
expect(log).toEqual(['after leave', 'dom leave', 'complete']);
539540
} else {
540541
expect(log).toEqual(['dom ' + event, 'after ' + event]);
541-
$$rAF.flush();
542+
$animate.flush();
542543
expect(log).toEqual(['dom ' + event, 'after ' + event, 'complete']);
543544
}
544545
});
@@ -547,7 +548,7 @@ describe("ngAnimate $$animateJs", function() {
547548
they("$prop should asynchronously render the $prop animation when a start/end animator object is returned",
548549
allEvents, function(event) {
549550

550-
inject(function($$rAF, $$AnimateRunner) {
551+
inject(function($animate, $$AnimateRunner) {
551552
var runner;
552553
animations[event] = function(element, a, b, c) {
553554
return {
@@ -565,12 +566,12 @@ describe("ngAnimate $$animateJs", function() {
565566
if (event === 'leave') {
566567
expect(log).toEqual(['start leave']);
567568
runner.end();
568-
$$rAF.flush();
569+
$animate.flush();
569570
expect(log).toEqual(['start leave', 'dom leave', 'complete']);
570571
} else {
571572
expect(log).toEqual(['dom ' + event, 'start ' + event]);
572573
runner.end();
573-
$$rAF.flush();
574+
$animate.flush();
574575
expect(log).toEqual(['dom ' + event, 'start ' + event, 'complete']);
575576
}
576577
});
@@ -579,7 +580,7 @@ describe("ngAnimate $$animateJs", function() {
579580
they("$prop should asynchronously render the $prop animation when an instance of $$AnimateRunner is returned",
580581
allEvents, function(event) {
581582

582-
inject(function($$rAF, $$AnimateRunner) {
583+
inject(function($animate, $$AnimateRunner) {
583584
var runner;
584585
animations[event] = function(element, a, b, c) {
585586
log.push('start ' + event);
@@ -593,19 +594,19 @@ describe("ngAnimate $$animateJs", function() {
593594
if (event === 'leave') {
594595
expect(log).toEqual(['start leave']);
595596
runner.end();
596-
$$rAF.flush();
597+
$animate.flush();
597598
expect(log).toEqual(['start leave', 'dom leave', 'complete']);
598599
} else {
599600
expect(log).toEqual(['dom ' + event, 'start ' + event]);
600601
runner.end();
601-
$$rAF.flush();
602+
$animate.flush();
602603
expect(log).toEqual(['dom ' + event, 'start ' + event, 'complete']);
603604
}
604605
});
605606
});
606607

607608
they("$prop should asynchronously reject the before animation if the callback function is called with false", otherEvents, function(event) {
608-
inject(function($$rAF, $rootScope) {
609+
inject(function($animate, $rootScope) {
609610
var beforeMethod = 'before' + event.charAt(0).toUpperCase() + event.substr(1);
610611
animations[beforeMethod] = function(element, a, b, c) {
611612
log.push('before ' + event);
@@ -624,13 +625,13 @@ describe("ngAnimate $$animateJs", function() {
624625
function() { log.push('fail'); });
625626

626627
expect(log).toEqual(['before ' + event]);
627-
$$rAF.flush();
628+
$animate.flush();
628629
expect(log).toEqual(['before ' + event, 'dom ' + event, 'fail']);
629630
});
630631
});
631632

632633
they("$prop should asynchronously reject the after animation if the callback function is called with false", allEvents, function(event) {
633-
inject(function($$rAF, $rootScope) {
634+
inject(function($animate, $rootScope) {
634635
animations[event] = function(element, a, b, c) {
635636
log.push('after ' + event);
636637
var done = getDoneFunction(arguments);
@@ -644,17 +645,17 @@ describe("ngAnimate $$animateJs", function() {
644645
var expectations = [];
645646
if (event === 'leave') {
646647
expect(log).toEqual(['after leave']);
647-
$$rAF.flush();
648+
$animate.flush();
648649
expect(log).toEqual(['after leave', 'dom leave', 'fail']);
649650
} else {
650651
expect(log).toEqual(['dom ' + event, 'after ' + event]);
651-
$$rAF.flush();
652+
$animate.flush();
652653
expect(log).toEqual(['dom ' + event, 'after ' + event, 'fail']);
653654
}
654655
});
655656
});
656657

657-
it('setClass should delegate down to addClass/removeClass if not defined', inject(function($$rAF) {
658+
it('setClass should delegate down to addClass/removeClass if not defined', inject(function($animate) {
658659
animations.addClass = function(element, done) {
659660
log.push('addClass');
660661
};
@@ -671,7 +672,7 @@ describe("ngAnimate $$animateJs", function() {
671672
}));
672673

673674
it('beforeSetClass should delegate down to beforeAddClass/beforeRemoveClass if not defined',
674-
inject(function($$rAF) {
675+
inject(function($animate) {
675676

676677
animations.beforeAddClass = function(element, className, done) {
677678
log.push('beforeAddClass');
@@ -686,13 +687,13 @@ describe("ngAnimate $$animateJs", function() {
686687
expect(animations.setClass).toBeFalsy();
687688

688689
runAnimation('setClass');
689-
$$rAF.flush();
690+
$animate.flush();
690691

691692
expect(log).toEqual(['beforeRemoveClass', 'beforeAddClass', 'dom setClass']);
692693
}));
693694

694695
it('leave should always ignore the `beforeLeave` animation',
695-
inject(function($$rAF) {
696+
inject(function($animate) {
696697

697698
animations.beforeLeave = function(element, done) {
698699
log.push('beforeLeave');
@@ -705,13 +706,13 @@ describe("ngAnimate $$animateJs", function() {
705706
};
706707

707708
runAnimation('leave');
708-
$$rAF.flush();
709+
$animate.flush();
709710

710711
expect(log).toEqual(['leave', 'dom leave']);
711712
}));
712713

713714
it('should allow custom events to be triggered',
714-
inject(function($$rAF) {
715+
inject(function($animate) {
715716

716717
animations.beforeFlex = function(element, done) {
717718
log.push('beforeFlex');
@@ -724,7 +725,7 @@ describe("ngAnimate $$animateJs", function() {
724725
};
725726

726727
runAnimation('flex');
727-
$$rAF.flush();
728+
$animate.flush();
728729

729730
expect(log).toEqual(['beforeFlex', 'dom flex', 'flex']);
730731
}));

‎test/ngAnimate/animateRunnerSpec.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
22

3-
describe('$$rAFMutex', function() {
3+
describe('$$animateAsyncRun', function() {
44
beforeEach(module('ngAnimate'));
55

66
it('should fire the callback only when one or more RAFs have passed',
7-
inject(function($$rAF, $$rAFMutex) {
7+
inject(function($$animateAsyncRun, $$rAF) {
88

9-
var trigger = $$rAFMutex();
9+
var trigger = $$animateAsyncRun();
1010
var called = false;
1111
trigger(function() {
1212
called = true;
@@ -18,9 +18,9 @@ describe('$$rAFMutex', function() {
1818
}));
1919

2020
it('should immediately fire the callback if a RAF has passed since construction',
21-
inject(function($$rAF, $$rAFMutex) {
21+
inject(function($$animateAsyncRun, $$rAF) {
2222

23-
var trigger = $$rAFMutex();
23+
var trigger = $$animateAsyncRun();
2424
$$rAF.flush();
2525

2626
var called = false;
@@ -89,7 +89,7 @@ describe("$$AnimateRunner", function() {
8989
they("should immediately resolve each combined runner in a bottom-up order when $prop is called",
9090
['end', 'cancel'], function(method) {
9191

92-
inject(function($$AnimateRunner, $$rAF) {
92+
inject(function($$AnimateRunner) {
9393
var runner1 = new $$AnimateRunner();
9494
var runner2 = new $$AnimateRunner();
9595
runner1.setHost(runner2);
@@ -206,7 +206,7 @@ describe("$$AnimateRunner", function() {
206206
they("should immediately resolve if and when all runners have been $prop",
207207
{ ended: 'end', cancelled: 'cancel' }, function(method) {
208208

209-
inject(function($$rAF, $$AnimateRunner) {
209+
inject(function($$AnimateRunner) {
210210
var runner1 = new $$AnimateRunner();
211211
var runner2 = new $$AnimateRunner();
212212
var runner3 = new $$AnimateRunner();
@@ -227,7 +227,7 @@ describe("$$AnimateRunner", function() {
227227
});
228228

229229
it("should return a status of `false` if one or more runners was cancelled",
230-
inject(function($$rAF, $$AnimateRunner) {
230+
inject(function($$AnimateRunner) {
231231

232232
var runner1 = new $$AnimateRunner();
233233
var runner2 = new $$AnimateRunner();

‎test/ngAnimate/animateSpec.js

+48-48
Large diffs are not rendered by default.

‎test/ngAnimate/animationSpec.js

+20-21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
describe('$$animation', function() {
44

55
beforeEach(module('ngAnimate'));
6+
beforeEach(module('ngAnimateMock'));
67

78
var element;
89
afterEach(function() {
@@ -14,14 +15,14 @@ describe('$$animation', function() {
1415
}));
1516

1617
it("should not run an animation if there are no drivers",
17-
inject(function($$animation, $$rAF, $rootScope) {
18+
inject(function($$animation, $animate, $rootScope) {
1819

1920
element = jqLite('<div></div>');
2021
var done = false;
2122
$$animation(element, 'someEvent').then(function() {
2223
done = true;
2324
});
24-
$$rAF.flush();
25+
$animate.flush();
2526
$rootScope.$digest();
2627
expect(done).toBe(true);
2728
}));
@@ -33,14 +34,14 @@ describe('$$animation', function() {
3334
return false;
3435
});
3536
});
36-
inject(function($$animation, $$rAF, $rootScope) {
37+
inject(function($$animation, $animate, $rootScope) {
3738
element = jqLite('<div></div>');
3839
var done = false;
3940
$$animation(element, 'someEvent').then(function() {
4041
done = true;
4142
});
4243
$rootScope.$digest();
43-
$$rAF.flush();
44+
$animate.flush();
4445
$rootScope.$digest();
4546
expect(done).toBe(true);
4647
});
@@ -195,7 +196,7 @@ describe('$$animation', function() {
195196
});
196197
});
197198

198-
inject(function($$animation, $rootScope, $$rAF) {
199+
inject(function($$animation, $rootScope, $animate) {
199200
var status, element = jqLite('<div></div>');
200201
var runner = $$animation(element, 'enter');
201202
runner.then(function() {
@@ -210,7 +211,7 @@ describe('$$animation', function() {
210211
event === 'resolve' ? runner.end() : runner.cancel();
211212

212213
// the resolve/rejection digest
213-
$$rAF.flush();
214+
$animate.flush();
214215
$rootScope.$digest();
215216

216217
expect(status).toBe(event);
@@ -306,7 +307,7 @@ describe('$$animation', function() {
306307

307308
they('should close the animation if runner.$prop() is called before the $postDigest phase kicks in',
308309
['end', 'cancel'], function(method) {
309-
inject(function($$animation, $rootScope, $$rAF) {
310+
inject(function($$animation, $rootScope, $animate) {
310311
var status;
311312
var runner = $$animation(element, 'someEvent');
312313
runner.then(function() { status = 'end'; },
@@ -316,7 +317,7 @@ describe('$$animation', function() {
316317
$rootScope.$digest();
317318
expect(runnerLog).toEqual([]);
318319

319-
$$rAF.flush();
320+
$animate.flush();
320321
expect(status).toBe(method);
321322
});
322323
});
@@ -363,11 +364,10 @@ describe('$$animation', function() {
363364
}));
364365

365366
it('should immediately end the animation if the element is removed from the DOM during the animation',
366-
inject(function($$animation, $$rAF, $rootScope) {
367+
inject(function($$animation, $animate, $rootScope) {
367368

368369
var runner = $$animation(element, 'someEvent');
369370
$rootScope.$digest();
370-
$$rAF.flush(); //the animation is "animating"
371371

372372
expect(capturedAnimation).toBeTruthy();
373373
expect(runnerLog).toEqual([]);
@@ -376,14 +376,13 @@ describe('$$animation', function() {
376376
}));
377377

378378
it('should not end the animation when the leave animation removes the element from the DOM',
379-
inject(function($$animation, $$rAF, $rootScope) {
379+
inject(function($$animation, $animate, $rootScope) {
380380

381381
var runner = $$animation(element, 'leave', {}, function() {
382382
element.remove();
383383
});
384384

385385
$rootScope.$digest();
386-
$$rAF.flush(); //the animation is "animating"
387386

388387
expect(runnerLog).toEqual([]);
389388
capturedAnimation.options.domOperation(); //this removes the element
@@ -392,7 +391,7 @@ describe('$$animation', function() {
392391
}));
393392

394393
it('should remove the $destroy event listener when the animation is closed',
395-
inject(function($$animation, $$rAF, $rootScope) {
394+
inject(function($$animation, $rootScope) {
396395

397396
var addListen = spyOn(element, 'on').andCallThrough();
398397
var removeListen = spyOn(element, 'off').andCallThrough();
@@ -408,7 +407,7 @@ describe('$$animation', function() {
408407
}));
409408

410409
it('should always sort parent-element animations to run in order of parent-to-child DOM structure',
411-
inject(function($$animation, $$rAF, $rootScope) {
410+
inject(function($$animation, $rootScope) {
412411

413412
var child = jqLite('<div></div>');
414413
var grandchild = jqLite('<div></div>');
@@ -649,7 +648,7 @@ describe('$$animation', function() {
649648
});
650649

651650
it("should not end the animation when the `from` animation calls its own leave dom operation",
652-
inject(function($$animation, $rootScope, $$rAF) {
651+
inject(function($$animation, $rootScope) {
653652

654653
fromElement.addClass('group-1');
655654
var elementRemoved = false;
@@ -679,7 +678,7 @@ describe('$$animation', function() {
679678
}));
680679

681680
it("should not end the animation if any of the anchor elements are removed from the DOM during the animation",
682-
inject(function($$animation, $rootScope, $$rAF) {
681+
inject(function($$animation, $rootScope) {
683682

684683
fromElement.addClass('group-1');
685684
var elementRemoved = false;
@@ -702,7 +701,7 @@ describe('$$animation', function() {
702701
}));
703702

704703
it('should prepare a parent-element animation to run first before the anchored animation',
705-
inject(function($$animation, $$rAF, $rootScope, $rootElement) {
704+
inject(function($$animation, $rootScope, $rootElement) {
706705

707706
fromAnchors[0].attr('ng-animate-ref', 'shared');
708707
toAnchors[0].attr('ng-animate-ref', 'shared');
@@ -869,7 +868,7 @@ describe('$$animation', function() {
869868
};
870869
});
871870
});
872-
inject(function($$animation, $rootScope, $$rAF) {
871+
inject(function($$animation, $rootScope, $animate) {
873872
element.addClass('four');
874873

875874
var completed = false;
@@ -882,7 +881,7 @@ describe('$$animation', function() {
882881

883882
$rootScope.$digest(); //runs the animation
884883
$rootScope.$digest(); //flushes the step code
885-
$$rAF.flush(); //runs the $$animation promise
884+
$animate.flush();
886885
$rootScope.$digest(); //the runner promise
887886

888887
expect(completed).toBe(true);
@@ -921,7 +920,7 @@ describe('$$animation', function() {
921920
};
922921
});
923922
});
924-
inject(function($$animation, $rootScope, $$rAF) {
923+
inject(function($$animation, $rootScope, $animate) {
925924
element.addClass('four');
926925

927926
var completed = false;
@@ -937,7 +936,7 @@ describe('$$animation', function() {
937936
$rootScope.$digest(); //flushes the step code
938937

939938
runner.end();
940-
$$rAF.flush(); //runs the $$animation promise
939+
$animate.flush();
941940
$rootScope.$digest(); //the runner promise
942941

943942
expect(completed).toBe(true);

‎test/ngAnimate/integrationSpec.js

+22-17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
describe('ngAnimate integration tests', function() {
44

55
beforeEach(module('ngAnimate'));
6+
beforeEach(module('ngAnimateMock'));
67

78
var element, html, ss;
89
beforeEach(module(function() {
@@ -30,7 +31,7 @@ describe('ngAnimate integration tests', function() {
3031
they('should render an $prop animation',
3132
['enter', 'leave', 'move', 'addClass', 'removeClass', 'setClass'], function(event) {
3233

33-
inject(function($animate, $compile, $rootScope, $rootElement, $$rAF) {
34+
inject(function($animate, $compile, $rootScope, $rootElement) {
3435
element = jqLite('<div class="animate-me"></div>');
3536
$compile(element)($rootScope);
3637

@@ -97,10 +98,11 @@ describe('ngAnimate integration tests', function() {
9798
});
9899

99100
expect(element).toHaveClass(setupClass);
100-
$$rAF.flush();
101+
$animate.flush();
101102
expect(element).toHaveClass(activeClass);
102103

103104
browserTrigger(element, 'transitionend', { timeStamp: Date.now(), elapsedTime: 2 });
105+
$animate.flush();
104106

105107
expect(element).not.toHaveClass(setupClass);
106108
expect(element).not.toHaveClass(activeClass);
@@ -112,7 +114,7 @@ describe('ngAnimate integration tests', function() {
112114
});
113115

114116
it('should not throw an error if the element is orphaned before the CSS animation starts',
115-
inject(function($rootScope, $rootElement, $animate, $$rAF) {
117+
inject(function($rootScope, $rootElement, $animate) {
116118

117119
ss.addRule('.animate-me', 'transition:2s linear all;');
118120

@@ -127,19 +129,19 @@ describe('ngAnimate integration tests', function() {
127129
$rootScope.$digest();
128130

129131
// this will run the first class-based animation
130-
$$rAF.flush();
132+
$animate.flush();
131133

132134
element.remove();
133135

134136
expect(function() {
135-
$$rAF.flush();
137+
$animate.flush();
136138
}).not.toThrow();
137139

138140
dealoc(element);
139141
}));
140142

141143
it('should always synchronously add css classes in order for child animations to animate properly',
142-
inject(function($animate, $compile, $rootScope, $rootElement, $$rAF, $document) {
144+
inject(function($animate, $compile, $rootScope, $rootElement, $document) {
143145

144146
ss.addRule('.animations-enabled .animate-me.ng-enter', 'transition:2s linear all;');
145147

@@ -160,18 +162,19 @@ describe('ngAnimate integration tests', function() {
160162
expect(element).toHaveClass('animations-enabled');
161163
expect(child).toHaveClass('ng-enter');
162164

163-
$$rAF.flush();
165+
$animate.flush();
164166

165167
expect(child).toHaveClass('ng-enter-active');
166168

167169
browserTrigger(child, 'transitionend', { timeStamp: Date.now(), elapsedTime: 2 });
170+
$animate.flush();
168171

169172
expect(child).not.toHaveClass('ng-enter-active');
170173
expect(child).not.toHaveClass('ng-enter');
171174
}));
172175

173176
it('should synchronously add/remove ng-class expressions in time for other animations to run on the same element',
174-
inject(function($animate, $compile, $rootScope, $rootElement, $$rAF, $document) {
177+
inject(function($animate, $compile, $rootScope, $rootElement, $document) {
175178

176179
ss.addRule('.animate-me.ng-enter.on', 'transition:2s linear all;');
177180

@@ -184,7 +187,7 @@ describe('ngAnimate integration tests', function() {
184187

185188
$rootScope.exp = true;
186189
$rootScope.$digest();
187-
$$rAF.flush();
190+
$animate.flush();
188191

189192
var child = element.find('div');
190193

@@ -203,18 +206,19 @@ describe('ngAnimate integration tests', function() {
203206
expect(child).toHaveClass('on');
204207
expect(child).toHaveClass('ng-enter');
205208

206-
$$rAF.flush();
209+
$animate.flush();
207210

208211
expect(child).toHaveClass('ng-enter-active');
209212

210213
browserTrigger(child, 'transitionend', { timeStamp: Date.now(), elapsedTime: 2 });
214+
$animate.flush();
211215

212216
expect(child).not.toHaveClass('ng-enter-active');
213217
expect(child).not.toHaveClass('ng-enter');
214218
}));
215219

216220
it('should animate ng-class and a structural animation in parallel on the same element',
217-
inject(function($animate, $compile, $rootScope, $rootElement, $$rAF, $document) {
221+
inject(function($animate, $compile, $rootScope, $rootElement, $document) {
218222

219223
ss.addRule('.animate-me.ng-enter', 'transition:2s linear all;');
220224
ss.addRule('.animate-me.expand', 'transition:5s linear all; font-size:200px;');
@@ -236,12 +240,13 @@ describe('ngAnimate integration tests', function() {
236240
expect(child).toHaveClass('expand-add');
237241
expect(child).toHaveClass('expand');
238242

239-
$$rAF.flush();
243+
$animate.flush();
240244

241245
expect(child).toHaveClass('ng-enter-active');
242246
expect(child).toHaveClass('expand-add-active');
243247

244248
browserTrigger(child, 'transitionend', { timeStamp: Date.now(), elapsedTime: 2 });
249+
$animate.flush();
245250

246251
expect(child).not.toHaveClass('ng-enter-active');
247252
expect(child).not.toHaveClass('ng-enter');
@@ -251,7 +256,7 @@ describe('ngAnimate integration tests', function() {
251256

252257
it('should issue a reflow for each element animation on all DOM levels', function() {
253258
module('ngAnimateMock');
254-
inject(function($animate, $compile, $rootScope, $rootElement, $$rAF, $document) {
259+
inject(function($animate, $compile, $rootScope, $rootElement, $document) {
255260
element = jqLite(
256261
'<div ng-class="{parent:exp}">' +
257262
'<div ng-class="{parent2:exp}">' +
@@ -281,7 +286,7 @@ describe('ngAnimate integration tests', function() {
281286

282287
it('should issue a reflow for each element and also its children', function() {
283288
module('ngAnimateMock');
284-
inject(function($animate, $compile, $rootScope, $rootElement, $$rAF, $document) {
289+
inject(function($animate, $compile, $rootScope, $rootElement, $document) {
285290
element = jqLite(
286291
'<div ng-class="{one:exp}">' +
287292
'<div ng-if="exp"></div>' +
@@ -312,7 +317,7 @@ describe('ngAnimate integration tests', function() {
312317

313318
it('should always issue atleast one reflow incase there are no parent class-based animations', function() {
314319
module('ngAnimateMock');
315-
inject(function($animate, $compile, $rootScope, $rootElement, $$rAF, $document) {
320+
inject(function($animate, $compile, $rootScope, $rootElement, $document) {
316321
element = jqLite(
317322
'<div ng-repeat="item in items" ng-class="{someAnimation:exp}">' +
318323
'{{ item }}' +
@@ -355,7 +360,7 @@ describe('ngAnimate integration tests', function() {
355360
});
356361
});
357362

358-
inject(function($animate, $compile, $rootScope, $rootElement, $$rAF) {
363+
inject(function($animate, $compile, $rootScope, $rootElement) {
359364
element = jqLite('<div class="animate-me"></div>');
360365
$compile(element)($rootScope);
361366

@@ -407,7 +412,7 @@ describe('ngAnimate integration tests', function() {
407412
expect(isFunction(endAnimation)).toBe(true);
408413

409414
endAnimation();
410-
$$rAF.flush();
415+
$animate.flush();
411416
expect(animateCompleteCallbackFired).toBe(true);
412417

413418
$rootScope.$digest();

‎test/ngRoute/directive/ngViewSpec.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,6 @@ describe('ngView animations', function() {
712712
$location.path('/foo');
713713
$rootScope.$digest();
714714

715-
$animate.triggerCallbacks();
716715

717716
$location.path('/');
718717
$rootScope.$digest();
@@ -810,7 +809,7 @@ describe('ngView animations', function() {
810809
});
811810
});
812811

813-
inject(function($rootScope, $compile, $location, $route, $timeout, $rootElement, $sniffer, $animate, $$rAF) {
812+
inject(function($rootScope, $compile, $location, $route, $timeout, $rootElement, $sniffer, $animate) {
814813
element = $compile(html('<div><ng:view onload="load()" class="my-animation"></ng:view></div>'))($rootScope);
815814
$animate.enabled(true);
816815

@@ -834,7 +833,7 @@ describe('ngView animations', function() {
834833
expect($animate.queue.shift().event).toBe('enter'); //ngRepeat 3
835834
expect($animate.queue.shift().event).toBe('enter'); //ngRepeat 4
836835

837-
$$rAF.flush();
836+
$animate.flush();
838837

839838
expect(element.text()).toEqual('34');
840839

@@ -913,9 +912,11 @@ describe('ngView animations', function() {
913912

914913
$location.path('/foo');
915914
$rootScope.$digest();
916-
expect($animate.queue.shift().event).toBe('enter');
917-
$animate.triggerCallbacks();
918915

916+
$animate.flush();
917+
$rootScope.$digest();
918+
919+
expect($animate.queue.shift().event).toBe('enter');
919920
expect(autoScrollSpy).toHaveBeenCalledOnce();
920921
}));
921922

@@ -927,9 +928,11 @@ describe('ngView animations', function() {
927928
$rootScope.value = true;
928929
$location.path('/foo');
929930
$rootScope.$digest();
930-
expect($animate.queue.shift().event).toBe('enter');
931-
$animate.triggerCallbacks();
932931

932+
$animate.flush();
933+
$rootScope.$digest();
934+
935+
expect($animate.queue.shift().event).toBe('enter');
933936
expect(autoScrollSpy).toHaveBeenCalledOnce();
934937
}));
935938

@@ -941,7 +944,6 @@ describe('ngView animations', function() {
941944
$location.path('/foo');
942945
$rootScope.$digest();
943946
expect($animate.queue.shift().event).toBe('enter');
944-
$animate.triggerCallbacks();
945947

946948
expect(autoScrollSpy).not.toHaveBeenCalled();
947949
}));
@@ -955,7 +957,6 @@ describe('ngView animations', function() {
955957
$location.path('/foo');
956958
$rootScope.$digest();
957959
expect($animate.queue.shift().event).toBe('enter');
958-
$animate.triggerCallbacks();
959960

960961
expect(autoScrollSpy).not.toHaveBeenCalled();
961962
}));
@@ -972,7 +973,9 @@ describe('ngView animations', function() {
972973
expect(autoScrollSpy).not.toHaveBeenCalled();
973974

974975
expect($animate.queue.shift().event).toBe('enter');
975-
$animate.triggerCallbacks();
976+
977+
$animate.flush();
978+
$rootScope.$digest();
976979

977980
expect($animate.enter).toHaveBeenCalledOnce();
978981
expect(autoScrollSpy).toHaveBeenCalledOnce();

0 commit comments

Comments
 (0)
Please sign in to comment.