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

Commit a801df7

Browse files
committed
fix(ngMock): ignore empty javascript animations in $animate.closeAndFlush()
1 parent cb74999 commit a801df7

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/ngMock/angular-mocks.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,10 @@ angular.mock.animate = angular.module('ngAnimateMock', ['ng'])
797797

798798
var animateJsConstructor = function() {
799799
var animator = $delegate.apply($delegate, arguments);
800-
runners.push(animator);
800+
// If no javascript animation is found, animator is undefined
801+
if (animator) {
802+
runners.push(animator);
803+
}
801804
return animator;
802805
};
803806

test/ngMock/angular-mocksSpec.js

+22
Original file line numberDiff line numberDiff line change
@@ -2230,12 +2230,34 @@ describe('ngMockE2E', function() {
22302230
expect(animationLog).toEqual(['start leave', 'end leave']);
22312231
}));
22322232

2233+
it('should not throw when a regular animation has no javascript animation',
2234+
inject(function($animate, $$animation, $rootElement) {
2235+
2236+
var element = jqLite('<div></div>');
2237+
$rootElement.append(element);
2238+
2239+
// Make sure the animation has valid $animateCss options
2240+
$$animation(element, null, {
2241+
from: { background: 'red' },
2242+
to: { background: 'blue' },
2243+
duration: 1,
2244+
transitionStyle: '1s linear all'
2245+
});
2246+
2247+
expect(function() {
2248+
$animate.closeAndFlush();
2249+
}).not.toThrow();
2250+
2251+
dealoc(element);
2252+
}));
2253+
22332254
it('should throw an error if there are no animations to close and flush',
22342255
inject(function($animate) {
22352256

22362257
expect(function() {
22372258
$animate.closeAndFlush();
22382259
}).toThrow('No pending animations ready to be closed or flushed');
2260+
22392261
}));
22402262
});
22412263
});

0 commit comments

Comments
 (0)