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

fix($animate): silently ignore the options param if an object is not passed in #11826

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/ng/animate.js
Expand Up @@ -12,6 +12,10 @@ function mergeClasses(a,b) {
return a + ' ' + b;
}

function makeAnimateOptions(options) {
return isObject(options) ? options : {};
}

function extractElementNode(element) {
for (var i = 0; i < element.length; i++) {
var elm = element[i];
Expand Down Expand Up @@ -406,6 +410,7 @@ var $AnimateProvider = ['$provide', function($provide) {
* @return {Promise} the animation callback promise
*/
enter: function(element, parent, after, options) {
options = makeAnimateOptions(options);
parent = parent || after.parent();
domInsert(element, parent, after);
return $$animateQueue.push(element, 'enter', options);
Expand All @@ -430,6 +435,7 @@ var $AnimateProvider = ['$provide', function($provide) {
* @return {Promise} the animation callback promise
*/
move: function(element, parent, after, options) {
options = makeAnimateOptions(options);
parent = parent || after.parent();
domInsert(element, parent, after);
return $$animateQueue.push(element, 'move', options);
Expand All @@ -449,6 +455,7 @@ var $AnimateProvider = ['$provide', function($provide) {
* @return {Promise} the animation callback promise
*/
leave: function(element, options) {
options = makeAnimateOptions(options);
return $$animateQueue.push(element, 'leave', options, function() {
element.remove();
});
Expand All @@ -473,7 +480,7 @@ var $AnimateProvider = ['$provide', function($provide) {
* @return {Promise} the animation callback promise
*/
addClass: function(element, className, options) {
options = options || {};
options = makeAnimateOptions(options);
options.addClass = mergeClasses(options.addclass, className);
return $$animateQueue.push(element, 'addClass', options);
},
Expand All @@ -497,7 +504,7 @@ var $AnimateProvider = ['$provide', function($provide) {
* @return {Promise} the animation callback promise
*/
removeClass: function(element, className, options) {
options = options || {};
options = makeAnimateOptions(options);
options.removeClass = mergeClasses(options.removeClass, className);
return $$animateQueue.push(element, 'removeClass', options);
},
Expand All @@ -522,7 +529,7 @@ var $AnimateProvider = ['$provide', function($provide) {
* @return {Promise} the animation callback promise
*/
setClass: function(element, add, remove, options) {
options = options || {};
options = makeAnimateOptions(options);
options.addClass = mergeClasses(options.addClass, add);
options.removeClass = mergeClasses(options.removeClass, remove);
return $$animateQueue.push(element, 'setClass', options);
Expand Down Expand Up @@ -550,7 +557,7 @@ var $AnimateProvider = ['$provide', function($provide) {
* @return {Promise} the animation callback promise
*/
animate: function(element, from, to, className, options) {
options = options || {};
options = makeAnimateOptions(options);
options.from = options.from ? extend(options.from, from) : from;
options.to = options.to ? extend(options.to, to) : to;

Expand Down
48 changes: 48 additions & 0 deletions test/ngAnimate/animateSpec.js
Expand Up @@ -486,6 +486,54 @@ describe("animations", function() {
});
});

they('$prop() shouldn\'t blow up when a function is passed as the options param',
['enter', 'move', 'leave', 'addClass', 'removeClass', 'setClass', 'animate'], function(event) {

inject(function($animate, $rootScope, $document) {
var element = $document[0].createElement('div');
element.setAttribute('id', 'crazy-man');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that left over from the previous test? The id is not used.

if (event !== 'enter' && event !== 'move') {
parent.append(element);
}

var fakeOption = function() { };

switch (event) {
case 'enter':
case 'move':
$animate[event](element, parent, parent2, fakeOption);
break;

case 'addClass':
$animate.addClass(element, 'klass', fakeOption);
break;

case 'removeClass':
element.className = 'klass';
$animate.removeClass(element, 'klass', fakeOption);
break;

case 'setClass':
element.className = 'two';
$animate.setClass(element, 'one', 'two', fakeOption);
break;

case 'leave':
$animate.leave(element, fakeOption);
break;

case 'animate':
var toStyles = { color: 'red' };
$animate.animate(element, {}, toStyles, 'klass', fakeOption);
break;
}

$rootScope.$digest();
var options = capturedAnimation[2];
expect(isObject(options)).toBeTruthy();
});
});

describe('addClass / removeClass', function() {
it('should not perform an animation if there are no valid CSS classes to add',
inject(function($animate, $rootScope) {
Expand Down