From ee22b57d1f7d454266389e0f0f2bfa8c88d2ceb2 Mon Sep 17 00:00:00 2001 From: Martin Staffa Date: Sat, 9 Jan 2016 13:32:57 +0100 Subject: [PATCH] fix(ngMock): ignore empty javascript animations in $animate.closeAndFlush() --- src/ngMock/angular-mocks.js | 5 ++++- test/ngMock/angular-mocksSpec.js | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index 6997d83a5dd0..d42a0687469c 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 14fb543eb374..684018106568 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -2148,12 +2148,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'); + })); }); });