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

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix($animateCss): don't unregister events none have been added
Browse files Browse the repository at this point in the history
Joining an empty array with ' ' results in an empty string,
which for jquery/jqlite is the same as calling .off() without any
argument.
Narretz committed Dec 11, 2015
1 parent e4e5677 commit 6d32907
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ngAnimate/animateCss.js
Original file line number Diff line number Diff line change
@@ -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);
}

31 changes: 31 additions & 0 deletions test/ngAnimate/animateCssSpec.js
Original file line number Diff line number Diff line change
@@ -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();
});
});

});
});

0 comments on commit 6d32907

Please sign in to comment.