angular-cn/packages/animations/test/animation_player_spec.ts
Joey Perrott d1ea1f4c7f build: update license headers to reference Google LLC ()
Update the license headers throughout the repository to reference Google LLC
rather than Google Inc, for the required license headers.

PR Close 
2020-05-26 14:26:58 -04:00

86 lines
2.6 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {fakeAsync} from '@angular/core/testing';
import {flushMicrotasks} from '../../core/testing/src/fake_async';
import {NoopAnimationPlayer} from '../src/players/animation_player';
import {scheduleMicroTask} from '../src/util';
{
describe('NoopAnimationPlayer', function() {
it('should finish after the next microtask once started', fakeAsync(() => {
const log: string[] = [];
const player = new NoopAnimationPlayer();
player.onStart(() => log.push('started'));
player.onDone(() => log.push('done'));
flushMicrotasks();
expect(log).toEqual([]);
player.play();
expect(log).toEqual(['started']);
flushMicrotasks();
expect(log).toEqual(['started', 'done']);
}));
it('should fire all callbacks when destroyed', () => {
const log: string[] = [];
const player = new NoopAnimationPlayer();
player.onStart(() => log.push('started'));
player.onDone(() => log.push('done'));
player.onDestroy(() => log.push('destroy'));
expect(log).toEqual([]);
player.destroy();
expect(log).toEqual(['started', 'done', 'destroy']);
});
it('should fire start/done callbacks manually when called directly', fakeAsync(() => {
const log: string[] = [];
const player = new NoopAnimationPlayer();
player.onStart(() => log.push('started'));
player.onDone(() => log.push('done'));
flushMicrotasks();
(player as any).triggerCallback('start');
expect(log).toEqual(['started']);
player.play();
expect(log).toEqual(['started']);
(player as any).triggerCallback('done');
expect(log).toEqual(['started', 'done']);
player.finish();
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();
expect(log).toEqual(['started', 'done']);
}));
});
}