From f79f4357ef8f1795435d7cc061a7f72562153240 Mon Sep 17 00:00:00 2001 From: Martin Staffa Date: Fri, 11 Dec 2015 12:20:31 +0100 Subject: [PATCH] fix($animateCss): don't unregister when events are empty --- src/ngAnimate/animateCss.js | 2 +- test/ngAnimate/animateCssSpec.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/ngAnimate/animateCss.js b/src/ngAnimate/animateCss.js index 1039db3425df..edff35f97fdb 100644 --- a/src/ngAnimate/animateCss.js +++ b/src/ngAnimate/animateCss.js @@ -750,7 +750,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) { } // Remove the transitionend / animationend listener(s) - if (events) { + if (events && events.length) { element.off(events.join(' '), onAnimationProgress); } diff --git a/test/ngAnimate/animateCssSpec.js b/test/ngAnimate/animateCssSpec.js index 4a828ecc372e..9a2fe8968177 100644 --- a/test/ngAnimate/animateCssSpec.js +++ b/test/ngAnimate/animateCssSpec.js @@ -1502,6 +1502,37 @@ describe("ngAnimate $animateCss", function() { expect(elementOffSpy.mostRecentCall.args[0]).toBe(event); }); }); + + they("should not add or remove $prop event listeners when end() is called before rAF has been triggered", + [TRANSITIONEND_EVENT, ANIMATIONEND_EVENT], function(event) { + inject(function($animateCss, $timeout) { + + setStyles(event); + + // Make sure other event listeners aren't removed by accident + var otherEndSpy = jasmine.createSpy('otherEndSpy'); + element.on(event, otherEndSpy); + + expect(elementOnSpy).toHaveBeenCalledOnce(); + elementOnSpy.reset(); + + var animator = $animateCss(element, { + event: 'enter', + structural: true + }); + + var runner = animator.start(); + expect(elementOnSpy).not.toHaveBeenCalled(); + + // This closes the animation before it has started + runner.end(); + expect(elementOffSpy).not.toHaveBeenCalled(); + + progress(element, 10); + expect(otherEndSpy).toHaveBeenCalledOnce(); + }); + }); + }); });