diff --git a/src/ngAnimate/animateQueue.js b/src/ngAnimate/animateQueue.js index 0fdadd508609..e024c831cf3c 100644 --- a/src/ngAnimate/animateQueue.js +++ b/src/ngAnimate/animateQueue.js @@ -586,6 +586,7 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) { parentHost = parentElement.data(NG_ANIMATE_PIN_DATA); if (parentHost) { parentElement = parentHost; + rootElementDetected = true; } } } diff --git a/src/ngAnimate/shared.js b/src/ngAnimate/shared.js index 501e5bd0d015..308258ec78c0 100644 --- a/src/ngAnimate/shared.js +++ b/src/ngAnimate/shared.js @@ -73,6 +73,7 @@ var isPromiseLike = function(p) { return p && p.then ? true : false; }; +var ngMinErr = angular.$$minErr('ng'); function assertArg(arg, name, reason) { if (!arg) { throw ngMinErr('areq', "Argument '{0}' is {1}", (name || '?'), (reason || "required")); diff --git a/test/ngAnimate/animateSpec.js b/test/ngAnimate/animateSpec.js index cdc91a59312d..dc665ead5398 100644 --- a/test/ngAnimate/animateSpec.js +++ b/test/ngAnimate/animateSpec.js @@ -1431,29 +1431,64 @@ describe("animations", function() { }); })); - it('should allow an element to pinned elsewhere and still be available in animations', - inject(function($animate, $compile, $document, $rootElement, $rootScope) { - - var innerParent = jqLite('
'); - jqLite($document[0].body).append(innerParent); - innerParent.append($rootElement); + it('should throw if the arguments are not elements', + inject(function($animate, $compile, $document, $rootScope, $rootElement) { var element = jqLite('
'); - jqLite($document[0].body).append(element); - $animate.addClass(element, 'red'); - $rootScope.$digest(); - expect(capturedAnimation).toBeFalsy(); + expect(function() { + $animate.pin(element); + }).toThrowMinErr('ng', 'areq', 'Argument \'parentElement\' is not an element'); - $animate.pin(element, $rootElement); - - $animate.addClass(element, 'blue'); - $rootScope.$digest(); - expect(capturedAnimation).toBeTruthy(); + expect(function() { + $animate.pin(null, $rootElement); + }).toThrowMinErr('ng', 'areq', 'Argument \'element\' is not an element'); dealoc(element); })); + + they('should animate an element inside a pinned element that is the $prop element', + ['same', 'parent', 'grandparent'], + function(elementRelation) { + inject(function($animate, $compile, $document, $rootElement, $rootScope) { + + var pinElement, animateElement; + + var innerParent = jqLite('
'); + jqLite($document[0].body).append(innerParent); + innerParent.append($rootElement); + + switch (elementRelation) { + case 'same': + pinElement = jqLite('
'); + break; + case 'parent': + pinElement = jqLite('
'); + break; + case 'grandparent': + pinElement = jqLite('
'); + break; + } + + jqLite($document[0].body).append(pinElement); + animateElement = jqLite($document[0].getElementById('animate')); + + $animate.addClass(animateElement, 'red'); + $rootScope.$digest(); + expect(capturedAnimation).toBeFalsy(); + + // Pin the element to the app root to enable animations + $animate.pin(pinElement, $rootElement); + + $animate.addClass(animateElement, 'blue'); + $rootScope.$digest(); + expect(capturedAnimation).toBeTruthy(); + + dealoc(pinElement); + }); + }); + it('should adhere to the disabled state of the hosted parent when an element is pinned', inject(function($animate, $compile, $document, $rootElement, $rootScope) {