fix(animations): always fire start and done callbacks in order for noop animations (#20570)

PR Close #20570
This commit is contained in:
Matias Niemelä 2017-11-21 14:29:39 -08:00 committed by Miško Hevery
parent 0e012c9669
commit ffb6dbeefe
3 changed files with 49 additions and 2 deletions

View File

@ -62,8 +62,8 @@ export class NoopAnimationPlayer implements AnimationPlayer {
init(): void {} init(): void {}
play(): void { play(): void {
if (!this.hasStarted()) { if (!this.hasStarted()) {
this.triggerMicrotask();
this._onStart(); this._onStart();
this.triggerMicrotask();
} }
this._started = true; this._started = true;
} }

View File

@ -6,9 +6,9 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {fakeAsync} from '@angular/core/testing'; import {fakeAsync} from '@angular/core/testing';
import {flushMicrotasks} from '../../core/testing/src/fake_async'; import {flushMicrotasks} from '../../core/testing/src/fake_async';
import {NoopAnimationPlayer} from '../src/players/animation_player'; import {NoopAnimationPlayer} from '../src/players/animation_player';
import {scheduleMicroTask} from '../src/util';
export function main() { export function main() {
describe('NoopAnimationPlayer', function() { describe('NoopAnimationPlayer', function() {
@ -61,6 +61,21 @@ export function main() {
player.finish(); player.finish();
expect(log).toEqual(['started', 'done']); expect(log).toEqual(['started', 'done']);
flushMicrotasks();
expect(log).toEqual(['started', 'done']);
}));
it('should fire off start callbacks before triggering the finish callback', fakeAsync(() => {
const log: string[] = [];
const player = new NoopAnimationPlayer();
player.onStart(() => { scheduleMicroTask(() => log.push('started')); });
player.onDone(() => log.push('done'));
expect(log).toEqual([]);
player.play();
expect(log).toEqual([]);
flushMicrotasks(); flushMicrotasks();
expect(log).toEqual(['started', 'done']); expect(log).toEqual(['started', 'done']);
})); }));

View File

@ -80,6 +80,38 @@ export function main() {
flushMicrotasks(); flushMicrotasks();
expect(cmp.status).toEqual('done'); expect(cmp.status).toEqual('done');
})); }));
it('should always run .start callbacks before .done callbacks even for noop animations',
fakeAsync(() => {
@Component({
selector: 'cmp',
template: `
<div [@myAnimation]="exp" (@myAnimation.start)="cb('start')" (@myAnimation.done)="cb('done')"></div>
`,
animations: [
trigger(
'myAnimation',
[
transition('* => go', []),
]),
]
})
class Cmp {
exp: any = false;
log: string[] = [];
cb(status: string) { this.log.push(status); }
}
TestBed.configureTestingModule({declarations: [Cmp]});
const fixture = TestBed.createComponent(Cmp);
const cmp = fixture.componentInstance;
cmp.exp = 'go';
fixture.detectChanges();
expect(cmp.log).toEqual([]);
flushMicrotasks();
expect(cmp.log).toEqual(['start', 'done']);
}));
}); });
describe('component fixture integration', () => { describe('component fixture integration', () => {