From bfb23afd6378721c7b64b0b2d3e942313024e4c9 Mon Sep 17 00:00:00 2001 From: Maksim Ryzhikov Date: Wed, 4 May 2016 19:18:00 +0300 Subject: [PATCH] fix(ngAnimate): ensure animations are not attempted on empty jqLite collection Without this fix animation throw a javascript exception `element.parent not a function` when we pass empty jqLite collection. Closes #14558 --- src/ngAnimate/shared.js | 2 +- test/ngAnimate/animateSpec.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ngAnimate/shared.js b/src/ngAnimate/shared.js index a2029d211480..54d3c95412ae 100644 --- a/src/ngAnimate/shared.js +++ b/src/ngAnimate/shared.js @@ -127,7 +127,7 @@ function stripCommentsFromElement(element) { if (element instanceof jqLite) { switch (element.length) { case 0: - return []; + return element; break; case 1: diff --git a/test/ngAnimate/animateSpec.js b/test/ngAnimate/animateSpec.js index 6bd18d456b3f..b5207a44dda8 100644 --- a/test/ngAnimate/animateSpec.js +++ b/test/ngAnimate/animateSpec.js @@ -394,6 +394,18 @@ describe("animations", function() { expect(capturedAnimation).toBeFalsy(); })); + it('should not attempt to perform an animation on an empty jqLite collection', + inject(function($rootScope, $animate) { + + element.html(''); + var emptyNode = jqLite(element[0].firstChild); + + $animate.addClass(emptyNode, 'some-class'); + $rootScope.$digest(); + + expect(capturedAnimation).toBeFalsy(); + })); + it('should perform the leave domOperation if a text node is used', inject(function($rootScope, $animate) {