refactor(animations): make animation testing work with fixture.whenRenderingDone

This commit is contained in:
Matias Niemelä
2017-05-12 17:32:51 -04:00
committed by Jason Aden
parent 8a6eb1ac78
commit 54a6e4ff9e
9 changed files with 149 additions and 23 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ChangeDetectorRef, ComponentRef, DebugElement, ElementRef, NgZone, getDebugNode} from '@angular/core';
import {ChangeDetectorRef, ComponentRef, DebugElement, ElementRef, NgZone, RendererFactory2, getDebugNode} from '@angular/core';
/**
@ -40,6 +40,7 @@ export class ComponentFixture<T> {
*/
changeDetectorRef: ChangeDetectorRef;
private _renderer: RendererFactory2|null|undefined;
private _isStable: boolean = true;
private _isDestroyed: boolean = false;
private _resolve: ((result: any) => void)|null = null;
@ -160,11 +161,22 @@ export class ComponentFixture<T> {
}
}
private _getRenderer() {
if (this._renderer === undefined) {
this._renderer = this.componentRef.injector.get(RendererFactory2, null);
}
return this._renderer as RendererFactory2 | null;
}
/**
* Get a promise that resolves when the ui state is stable following animations.
*/
* Get a promise that resolves when the ui state is stable following animations.
*/
whenRenderingDone(): Promise<any> {
// this is temporary until this is functional
const renderer = this._getRenderer();
if (renderer && renderer.whenRenderingDone) {
return renderer.whenRenderingDone();
}
return this.whenStable();
}