@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ChangeDetectorRef, ComponentRef, DebugElement, ElementRef, NgZone, RendererFactory2, getDebugNode} from '@angular/core';
|
||||
import {ChangeDetectorRef, ComponentRef, DebugElement, ElementRef, getDebugNode, NgZone, RendererFactory2} from '@angular/core';
|
||||
|
||||
|
||||
/**
|
||||
@ -65,8 +65,11 @@ export class ComponentFixture<T> {
|
||||
// Create subscriptions outside the NgZone so that the callbacks run oustide
|
||||
// of NgZone.
|
||||
ngZone.runOutsideAngular(() => {
|
||||
this._onUnstableSubscription =
|
||||
ngZone.onUnstable.subscribe({next: () => { this._isStable = false; }});
|
||||
this._onUnstableSubscription = ngZone.onUnstable.subscribe({
|
||||
next: () => {
|
||||
this._isStable = false;
|
||||
}
|
||||
});
|
||||
this._onMicrotaskEmptySubscription = ngZone.onMicrotaskEmpty.subscribe({
|
||||
next: () => {
|
||||
if (this._autoDetect) {
|
||||
@ -87,7 +90,7 @@ export class ComponentFixture<T> {
|
||||
scheduleMicroTask(() => {
|
||||
if (!ngZone.hasPendingMacrotasks) {
|
||||
if (this._promise !== null) {
|
||||
this._resolve !(true);
|
||||
this._resolve!(true);
|
||||
this._resolve = null;
|
||||
this._promise = null;
|
||||
}
|
||||
@ -97,8 +100,11 @@ export class ComponentFixture<T> {
|
||||
}
|
||||
});
|
||||
|
||||
this._onErrorSubscription =
|
||||
ngZone.onError.subscribe({next: (error: any) => { throw error; }});
|
||||
this._onErrorSubscription = ngZone.onError.subscribe({
|
||||
next: (error: any) => {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -117,7 +123,9 @@ export class ComponentFixture<T> {
|
||||
if (this.ngZone != null) {
|
||||
// Run the change detection inside the NgZone so that any async tasks as part of the change
|
||||
// detection are captured by the zone and can be waited for in isStable.
|
||||
this.ngZone.run(() => { this._tick(checkNoChanges); });
|
||||
this.ngZone.run(() => {
|
||||
this._tick(checkNoChanges);
|
||||
});
|
||||
} else {
|
||||
// Running without zone. Just do the change detection.
|
||||
this._tick(checkNoChanges);
|
||||
@ -127,7 +135,9 @@ export class ComponentFixture<T> {
|
||||
/**
|
||||
* Do a change detection run to make sure there were no changes.
|
||||
*/
|
||||
checkNoChanges(): void { this.changeDetectorRef.checkNoChanges(); }
|
||||
checkNoChanges(): void {
|
||||
this.changeDetectorRef.checkNoChanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether the fixture should autodetect changes.
|
||||
@ -146,7 +156,9 @@ export class ComponentFixture<T> {
|
||||
* Return whether the fixture is currently stable or has async tasks that have not been completed
|
||||
* yet.
|
||||
*/
|
||||
isStable(): boolean { return this._isStable && !this.ngZone !.hasPendingMacrotasks; }
|
||||
isStable(): boolean {
|
||||
return this._isStable && !this.ngZone!.hasPendingMacrotasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a promise that resolves when the fixture is stable.
|
||||
@ -160,7 +172,9 @@ export class ComponentFixture<T> {
|
||||
} else if (this._promise !== null) {
|
||||
return this._promise;
|
||||
} else {
|
||||
this._promise = new Promise(res => { this._resolve = res; });
|
||||
this._promise = new Promise(res => {
|
||||
this._resolve = res;
|
||||
});
|
||||
return this._promise;
|
||||
}
|
||||
}
|
||||
@ -174,8 +188,8 @@ export class ComponentFixture<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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> {
|
||||
const renderer = this._getRenderer();
|
||||
if (renderer && renderer.whenRenderingDone) {
|
||||
|
Reference in New Issue
Block a user