Skip to content

Commit ee22b57

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

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
@@ -2148,12 +2148,34 @@ describe('ngMockE2E', function() {
21482148
expect(animationLog).toEqual(['start leave', 'end leave']);
21492149
}));
21502150

2151+
it('should not throw when a regular animation has no javascript animation',
2152+
inject(function($animate, $$animation, $rootElement) {
2153+
2154+
var element = jqLite('<div></div>');
2155+
$rootElement.append(element);
2156+
2157+
// Make sure the animation has valid $animateCss options
2158+
$$animation(element, null, {
2159+
from: { background: 'red' },
2160+
to: { background: 'blue' },
2161+
duration: 1,
2162+
transitionStyle: '1s linear all'
2163+
});
2164+
2165+
expect(function() {
2166+
$animate.closeAndFlush();
2167+
}).not.toThrow();
2168+
2169+
dealoc(element);
2170+
}));
2171+
21512172
it('should throw an error if there are no animations to close and flush',
21522173
inject(function($animate) {
21532174

21542175
expect(function() {
21552176
$animate.closeAndFlush();
21562177
}).toThrow('No pending animations ready to be closed or flushed');
2178+
21572179
}));
21582180
});
21592181
});

0 commit comments

Comments
 (0)