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

Commit 55b0014

Browse files
committed
test(ngAnimate): test calling callbacks for various constellations
1 parent 23550b5 commit 55b0014

File tree

1 file changed

+77
-9
lines changed

1 file changed

+77
-9
lines changed

test/ngAnimate/animateSpec.js

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ describe("animations", function() {
12561256
expect(element).not.toHaveClass('green');
12571257
}));
12581258

1259-
it('should automatically cancel out class-based animations if the element already contains or doesn\' contain the applied classes',
1259+
it('should automatically cancel out class-based animations if the element already contains or doesn\'t contain the applied classes',
12601260
inject(function($animate, $rootScope) {
12611261

12621262
parent.append(element);
@@ -2137,7 +2137,7 @@ describe("animations", function() {
21372137
});
21382138
});
21392139

2140-
describe('when animations are skipped', function() {
2140+
describe('when animations are skipped, disabled, or invalid', function() {
21412141

21422142
var overriddenAnimationRunner;
21432143
var capturedAnimation;
@@ -2186,19 +2186,87 @@ describe("animations", function() {
21862186
$rootScope.$digest();
21872187
$animate.flush();
21882188

2189-
expect(moveSpy.callCount).toBe(1);
2190-
expect(moveSpy.calls[0].args[1]).toBe('start');
2189+
expect(moveSpy.calls.count()).toBe(1);
2190+
expect(moveSpy.calls.mostRecent().args[1]).toBe('start');
21912191

21922192
$animate.leave(element);
21932193
$rootScope.$digest();
21942194
$animate.flush();
21952195

2196-
expect(moveSpy.callCount).toBe(2);
2197-
expect(moveSpy.calls[1].args[1]).toBe('close');
2196+
expect(moveSpy.calls.count()).toBe(2);
2197+
expect(moveSpy.calls.mostRecent().args[1]).toBe('close');
21982198

2199-
expect(leaveSpy.callCount).toBe(2);
2200-
expect(leaveSpy.calls[0].args[1]).toBe('start');
2201-
expect(leaveSpy.calls[1].args[1]).toBe('close');
2199+
expect(leaveSpy.calls.count()).toBe(2);
2200+
expect(leaveSpy.calls.argsFor(0)[1]).toBe('start');
2201+
expect(leaveSpy.calls.argsFor(1)[1]).toBe('close');
2202+
}));
2203+
2204+
2205+
it('should not trigger callbacks for the previous structural animation if a follow-up structural animation takes over before the postDigest',
2206+
inject(function($animate, $rootScope) {
2207+
2208+
var enterDone = jasmine.createSpy('enter animation done');
2209+
2210+
var enterSpy = jasmine.createSpy();
2211+
var leaveSpy = jasmine.createSpy();
2212+
2213+
$animate.on('enter', parent, enterSpy);
2214+
$animate.on('leave', parent, leaveSpy);
2215+
2216+
$animate.enter(element, parent).done(enterDone);
2217+
expect(enterDone).not.toHaveBeenCalled();
2218+
2219+
var runner = $animate.leave(element);
2220+
$animate.flush();
2221+
expect(enterDone).toHaveBeenCalled();
2222+
2223+
expect(enterSpy).not.toHaveBeenCalled();
2224+
expect(leaveSpy.calls.count()).toBe(1);
2225+
expect(leaveSpy.calls.mostRecent().args[1]).toBe('start');
2226+
2227+
leaveSpy.calls.reset();
2228+
runner.end();
2229+
$animate.flush();
2230+
2231+
expect(enterSpy).not.toHaveBeenCalled();
2232+
expect(leaveSpy.calls.count()).toBe(1);
2233+
expect(leaveSpy.calls.mostRecent().args[1]).toBe('close');
2234+
}));
2235+
2236+
2237+
it('should not trigger the callback if animations are disabled on the element',
2238+
inject(function($animate, $rootScope, $rootElement, $document) {
2239+
2240+
var callbackTriggered = false;
2241+
var spy = jasmine.createSpy('enter');
2242+
$animate.on('enter', jqLite($document[0].body), spy);
2243+
2244+
element = jqLite('<div></div>');
2245+
$animate.enabled(element, false);
2246+
var runner = $animate.enter(element, $rootElement);
2247+
$rootScope.$digest();
2248+
2249+
$animate.flush(); // Flushes the animation frames for the callbacks
2250+
2251+
expect(spy).not.toHaveBeenCalled();
2252+
}));
2253+
2254+
2255+
it('should not trigger the callbacks if the animation is skipped because there are no class-based animations and no structural animation',
2256+
inject(function($animate, $rootScope) {
2257+
2258+
parent.append(element);
2259+
var classSpy = jasmine.createSpy('classChange');
2260+
$animate.on('addClass', element, classSpy);
2261+
$animate.on('removeClass', element, classSpy);
2262+
element.addClass('one three');
2263+
2264+
$animate.addClass(element, 'one');
2265+
$animate.removeClass(element, 'four');
2266+
2267+
$rootScope.$digest();
2268+
$animate.flush();
2269+
expect(classSpy).not.toHaveBeenCalled();
22022270
}));
22032271

22042272
});

0 commit comments

Comments
 (0)