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

Commit 90da305

Browse files
committed
fix(ngAnimate): fire callbacks in the correct order for certain skipped animations
1 parent 651fd05 commit 90da305

File tree

2 files changed

+71
-5
lines changed

2 files changed

+71
-5
lines changed

src/ngAnimate/animateQueue.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,11 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
509509
markElementAnimationState(element, RUNNING_STATE);
510510
var realRunner = $$animation(element, event, animationDetails.options);
511511

512+
// this will update the runner's flow-control events based on
513+
// the `realRunner` object.
514+
runner.setHost(realRunner);
515+
notifyProgress(runner, event, 'start', {});
516+
512517
realRunner.done(function(status) {
513518
close(!status);
514519
var animationDetails = activeAnimationsLookup.get(node);
@@ -517,11 +522,6 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
517522
}
518523
notifyProgress(runner, event, 'close', {});
519524
});
520-
521-
// this will update the runner's flow-control events based on
522-
// the `realRunner` object.
523-
runner.setHost(realRunner);
524-
notifyProgress(runner, event, 'start', {});
525525
});
526526

527527
return runner;

test/ngAnimate/animateSpec.js

+66
Original file line numberDiff line numberDiff line change
@@ -2191,5 +2191,71 @@ describe("animations", function() {
21912191
});
21922192
});
21932193

2194+
describe('when animations are skipped', function() {
2195+
2196+
var overriddenAnimationRunner;
2197+
var capturedAnimation;
2198+
var capturedAnimationHistory;
2199+
var defaultFakeAnimationRunner;
2200+
var parent;
2201+
var parent2;
2202+
2203+
beforeEach(module(function($provide) {
2204+
overriddenAnimationRunner = null;
2205+
capturedAnimation = null;
2206+
capturedAnimationHistory = [];
2207+
2208+
$provide.value('$$animation', function() {
2209+
capturedAnimationHistory.push(capturedAnimation = arguments);
2210+
return overriddenAnimationRunner || defaultFakeAnimationRunner;
2211+
});
2212+
2213+
return function($rootElement, $q, $animate, $$AnimateRunner, $document) {
2214+
defaultFakeAnimationRunner = new $$AnimateRunner();
2215+
$animate.enabled(true);
2216+
2217+
element = jqLite('<div class="element">element</div>');
2218+
parent = jqLite('<div class="parent1">parent</div>');
2219+
parent2 = jqLite('<div class="parent2">parent</div>');
2220+
2221+
$rootElement.append(parent);
2222+
$rootElement.append(parent2);
2223+
jqLite($document[0].body).append($rootElement);
2224+
};
2225+
}));
2226+
2227+
2228+
it('should trigger all callbacks if a follow-up structural animation takes over a running animation',
2229+
inject(function($animate, $rootScope) {
2230+
2231+
parent.append(element);
2232+
var moveSpy = jasmine.createSpy();
2233+
var leaveSpy = jasmine.createSpy();
2234+
2235+
$animate.on('move', parent2, moveSpy);
2236+
$animate.on('leave', parent2, leaveSpy);
2237+
2238+
$animate.move(element, parent2);
2239+
2240+
$rootScope.$digest();
2241+
$animate.flush();
2242+
2243+
expect(moveSpy.callCount).toBe(1);
2244+
expect(moveSpy.calls[0].args[1]).toBe('start');
2245+
2246+
$animate.leave(element);
2247+
$rootScope.$digest();
2248+
$animate.flush();
2249+
2250+
expect(moveSpy.callCount).toBe(2);
2251+
expect(moveSpy.calls[1].args[1]).toBe('close');
2252+
2253+
expect(leaveSpy.callCount).toBe(2);
2254+
expect(leaveSpy.calls[0].args[1]).toBe('start');
2255+
expect(leaveSpy.calls[1].args[1]).toBe('close');
2256+
}));
2257+
2258+
});
2259+
21942260
});
21952261
});

0 commit comments

Comments
 (0)