fix(testing): ComponentFixture - Avoid extra scheduleMicrotask (#10223)

Don't schedule microtask to check for pending macrotasks when no one is waiting for a whenStable().
This commit is contained in:
vikerman 2016-07-22 16:07:11 -07:00 committed by Victor Berchet
parent 190bcc89c1
commit e34eb4520f
1 changed files with 13 additions and 9 deletions

View File

@ -87,16 +87,20 @@ export class ComponentFixture<T> {
});
this._onStableSubscription = ObservableWrapper.subscribe(ngZone.onStable, (_) => {
this._isStable = true;
// Check whether there are no pending macrotasks in a microtask so that ngZone gets a chance
// to update the state of pending macrotasks.
scheduleMicroTask(() => {
if (!this.ngZone.hasPendingMacrotasks) {
if (this._completer != null) {
this._completer.resolve(true);
this._completer = null;
// Check whether there is a pending whenStable() completer to resolve.
if (this._completer !== null) {
// If so check whether there are no pending macrotasks before resolving.
// Do this check in the next tick so that ngZone gets a chance to update the state of
// pending macrotasks.
scheduleMicroTask(() => {
if (!this.ngZone.hasPendingMacrotasks) {
if (this._completer !== null) {
this._completer.resolve(true);
this._completer = null;
}
}
}
});
});
}
});
this._onErrorSubscription = ObservableWrapper.subscribe(