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

Commit 23550b5

Browse files
committed
fix(ngAnimate): fire callbacks in the correct order for certain skipped animations
1 parent 97d2a08 commit 23550b5

File tree

2 files changed

+71
-5
lines changed

2 files changed

+71
-5
lines changed

src/ngAnimate/animateQueue.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
497497
markElementAnimationState(element, RUNNING_STATE);
498498
var realRunner = $$animation(element, event, animationDetails.options);
499499

500+
// this will update the runner's flow-control events based on
501+
// the `realRunner` object.
502+
runner.setHost(realRunner);
503+
notifyProgress(runner, event, 'start', {});
504+
500505
realRunner.done(function(status) {
501506
close(!status);
502507
var animationDetails = activeAnimationsLookup.get(node);
@@ -505,11 +510,6 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
505510
}
506511
notifyProgress(runner, event, 'close', {});
507512
});
508-
509-
// this will update the runner's flow-control events based on
510-
// the `realRunner` object.
511-
runner.setHost(realRunner);
512-
notifyProgress(runner, event, 'start', {});
513513
});
514514

515515
return runner;

test/ngAnimate/animateSpec.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,5 +2137,71 @@ describe("animations", function() {
21372137
});
21382138
});
21392139

2140+
describe('when animations are skipped', function() {
2141+
2142+
var overriddenAnimationRunner;
2143+
var capturedAnimation;
2144+
var capturedAnimationHistory;
2145+
var defaultFakeAnimationRunner;
2146+
var parent;
2147+
var parent2;
2148+
2149+
beforeEach(module(function($provide) {
2150+
overriddenAnimationRunner = null;
2151+
capturedAnimation = null;
2152+
capturedAnimationHistory = [];
2153+
2154+
$provide.value('$$animation', function() {
2155+
capturedAnimationHistory.push(capturedAnimation = arguments);
2156+
return overriddenAnimationRunner || defaultFakeAnimationRunner;
2157+
});
2158+
2159+
return function($rootElement, $q, $animate, $$AnimateRunner, $document) {
2160+
defaultFakeAnimationRunner = new $$AnimateRunner();
2161+
$animate.enabled(true);
2162+
2163+
element = jqLite('<div class="element">element</div>');
2164+
parent = jqLite('<div class="parent1">parent</div>');
2165+
parent2 = jqLite('<div class="parent2">parent</div>');
2166+
2167+
$rootElement.append(parent);
2168+
$rootElement.append(parent2);
2169+
jqLite($document[0].body).append($rootElement);
2170+
};
2171+
}));
2172+
2173+
2174+
it('should trigger all callbacks if a follow-up structural animation takes over a running animation',
2175+
inject(function($animate, $rootScope) {
2176+
2177+
parent.append(element);
2178+
var moveSpy = jasmine.createSpy();
2179+
var leaveSpy = jasmine.createSpy();
2180+
2181+
$animate.on('move', parent2, moveSpy);
2182+
$animate.on('leave', parent2, leaveSpy);
2183+
2184+
$animate.move(element, parent2);
2185+
2186+
$rootScope.$digest();
2187+
$animate.flush();
2188+
2189+
expect(moveSpy.callCount).toBe(1);
2190+
expect(moveSpy.calls[0].args[1]).toBe('start');
2191+
2192+
$animate.leave(element);
2193+
$rootScope.$digest();
2194+
$animate.flush();
2195+
2196+
expect(moveSpy.callCount).toBe(2);
2197+
expect(moveSpy.calls[1].args[1]).toBe('close');
2198+
2199+
expect(leaveSpy.callCount).toBe(2);
2200+
expect(leaveSpy.calls[0].args[1]).toBe('start');
2201+
expect(leaveSpy.calls[1].args[1]).toBe('close');
2202+
}));
2203+
2204+
});
2205+
21402206
});
21412207
});

0 commit comments

Comments
 (0)