From 9240e6438aacdda51d4581d76b204c0bc571a042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Fri, 21 Aug 2015 13:40:53 -0700 Subject: [PATCH] fix($animateCss): do not throw errors when a closing timeout is fired on a removed element Closes #12650 --- src/ngAnimate/animateCss.js | 12 +++++++++--- test/ngAnimate/animateCssSpec.js | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/ngAnimate/animateCss.js b/src/ngAnimate/animateCss.js index f706e13c06a2..8570ea313798 100644 --- a/src/ngAnimate/animateCss.js +++ b/src/ngAnimate/animateCss.js @@ -894,10 +894,16 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) { function onAnimationExpired() { var animationsData = element.data(ANIMATE_TIMER_KEY); - for (var i = 1; i < animationsData.length; i++) { - animationsData[i](); + + // this will be false in the event that the element was + // removed from the DOM (via a leave animation or something + // similar) + if (animationsData) { + for (var i = 1; i < animationsData.length; i++) { + animationsData[i](); + } + element.removeData(ANIMATE_TIMER_KEY); } - element.removeData(ANIMATE_TIMER_KEY); } function onAnimationProgress(event) { diff --git a/test/ngAnimate/animateCssSpec.js b/test/ngAnimate/animateCssSpec.js index e06dd6dcc764..6a68556e298b 100644 --- a/test/ngAnimate/animateCssSpec.js +++ b/test/ngAnimate/animateCssSpec.js @@ -1198,6 +1198,24 @@ describe("ngAnimate $animateCss", function() { return animator; } })); + + it("should not throw an error any pending timeout requests resolve after the element has already been removed", + inject(function($animateCss, $$body, $rootElement, $timeout, $animate) { + + var element = jqLite('
'); + $rootElement.append(element); + $$body.append($rootElement); + + ss.addRule('.red', 'transition:1s linear all;'); + + $animateCss(element, { addClass: 'red' }).start(); + triggerAnimationStartFrame(); + element.remove(); + + expect(function() { + $timeout.flush(); + }).not.toThrow(); + })); }); describe("getComputedStyle", function() {