Skip to content

Commit 181efa9

Browse files
committed
fix(ng.$animate): forward cancel to animation runner
1 parent 83519f5 commit 181efa9

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/ng/animate.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ var $AnimateProvider = ['$provide', /** @this */ function($provide) {
416416
* @param {Promise} animationPromise The animation promise that is returned when an animation is started.
417417
*/
418418
cancel: function(runner) {
419-
if (runner.end) {
420-
runner.end();
419+
if (runner.cancel) {
420+
runner.cancel();
421421
}
422422
},
423423

test/ng/animateSpec.js

+27
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,33 @@ describe('$animate', function() {
530530
}));
531531

532532

533+
it('should reject the promise when the animation is cancelled', inject(function(log, $animate, $$rAF, $rootScope) {
534+
element = jqLite('<p class="test2">test</p>');
535+
536+
var addRunner = $animate.addClass(element, 'test1');
537+
addRunner.then(function() {
538+
log('addClass(test1)success');
539+
}).catch(function() {
540+
log('addClass(test1)error');
541+
});
542+
543+
544+
var removeRunner = $animate.removeClass(element, 'test2');
545+
removeRunner.then(function() {
546+
log('removeClass(test2)success');
547+
}).catch(function() {
548+
log('removeClass(test2)error');
549+
});
550+
551+
$rootScope.$digest();
552+
expect(log).toEqual([]);
553+
$animate.cancel(addRunner);
554+
$animate.cancel(removeRunner);
555+
$rootScope.$digest();
556+
expect(log.toArray()).toEqual(['addClass(test1)error', 'removeClass(test2)error']);
557+
}));
558+
559+
533560
it('should defer class manipulation until end of digest for SVG', inject(function($rootScope, $animate) {
534561
if (!window.SVGElement) return;
535562
setupClassManipulationSpies();

0 commit comments

Comments
 (0)