Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit f79f435

Browse files
committed
fix($animateCss): don't unregister when events are empty
1 parent e4e5677 commit f79f435

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/ngAnimate/animateCss.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
750750
}
751751

752752
// Remove the transitionend / animationend listener(s)
753-
if (events) {
753+
if (events && events.length) {
754754
element.off(events.join(' '), onAnimationProgress);
755755
}
756756

test/ngAnimate/animateCssSpec.js

+31
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,37 @@ describe("ngAnimate $animateCss", function() {
15021502
expect(elementOffSpy.mostRecentCall.args[0]).toBe(event);
15031503
});
15041504
});
1505+
1506+
they("should not add or remove $prop event listeners when end() is called before rAF has been triggered",
1507+
[TRANSITIONEND_EVENT, ANIMATIONEND_EVENT], function(event) {
1508+
inject(function($animateCss, $timeout) {
1509+
1510+
setStyles(event);
1511+
1512+
// Make sure other event listeners aren't removed by accident
1513+
var otherEndSpy = jasmine.createSpy('otherEndSpy');
1514+
element.on(event, otherEndSpy);
1515+
1516+
expect(elementOnSpy).toHaveBeenCalledOnce();
1517+
elementOnSpy.reset();
1518+
1519+
var animator = $animateCss(element, {
1520+
event: 'enter',
1521+
structural: true
1522+
});
1523+
1524+
var runner = animator.start();
1525+
expect(elementOnSpy).not.toHaveBeenCalled();
1526+
1527+
// This closes the animation before it has started
1528+
runner.end();
1529+
expect(elementOffSpy).not.toHaveBeenCalled();
1530+
1531+
progress(element, 10);
1532+
expect(otherEndSpy).toHaveBeenCalledOnce();
1533+
});
1534+
});
1535+
15051536
});
15061537
});
15071538

0 commit comments

Comments
 (0)