diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index 3910cca15baa..6a391832c638 100644 --- a/src/ngMock/angular-mocks.js +++ b/src/ngMock/angular-mocks.js @@ -797,7 +797,10 @@ angular.mock.animate = angular.module('ngAnimateMock', ['ng']) var animateJsConstructor = function() { var animator = $delegate.apply($delegate, arguments); - runners.push(animator); + // If no javascript animation is found, animator is undefined + if (animator) { + runners.push(animator); + } return animator; }; diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index 818d33e3003a..cdee629c6d40 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -2230,12 +2230,34 @@ describe('ngMockE2E', function() { expect(animationLog).toEqual(['start leave', 'end leave']); })); + it('should not throw when a regular animation has no javascript animation', + inject(function($animate, $$animation, $rootElement) { + + var element = jqLite('
'); + $rootElement.append(element); + + // Make sure the animation has valid $animateCss options + $$animation(element, null, { + from: { background: 'red' }, + to: { background: 'blue' }, + duration: 1, + transitionStyle: '1s linear all' + }); + + expect(function() { + $animate.closeAndFlush(); + }).not.toThrow(); + + dealoc(element); + })); + it('should throw an error if there are no animations to close and flush', inject(function($animate) { expect(function() { $animate.closeAndFlush(); }).toThrow('No pending animations ready to be closed or flushed'); + })); }); });