From 3593d8580739bf71454e574e5144135cc55d1a03 Mon Sep 17 00:00:00 2001 From: Yegor Jbanov Date: Tue, 3 Nov 2015 18:45:55 -0800 Subject: [PATCH] fix: remove deprecated zone API usage in testability Closes #5084 --- .../src/core/testability/testability.ts | 18 ++++++++----- .../test/core/testability/testability_spec.ts | 25 +++++++++---------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/modules/angular2/src/core/testability/testability.ts b/modules/angular2/src/core/testability/testability.ts index 4d0f6d6ecd..66c2894685 100644 --- a/modules/angular2/src/core/testability/testability.ts +++ b/modules/angular2/src/core/testability/testability.ts @@ -4,7 +4,7 @@ import {Map, MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection' import {CONST, CONST_EXPR} from 'angular2/src/core/facade/lang'; import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions'; import {NgZone} from '../zone/ng_zone'; -import {PromiseWrapper} from 'angular2/src/core/facade/async'; +import {PromiseWrapper, ObservableWrapper} from 'angular2/src/core/facade/async'; /** @@ -24,11 +24,17 @@ export class Testability { /** @internal */ _watchAngularEvents(_ngZone: NgZone): void { - _ngZone.overrideOnTurnStart(() => { this._isAngularEventPending = true; }); - _ngZone.overrideOnEventDone(() => { - this._isAngularEventPending = false; - this._runCallbacksIfReady(); - }, true); + ObservableWrapper.subscribe(_ngZone.onTurnStart, + (_) => { this._isAngularEventPending = true; }); + + _ngZone.runOutsideAngular(() => { + ObservableWrapper.subscribe(_ngZone.onEventDone, (_) => { + if (!_ngZone.hasPendingTimers) { + this._isAngularEventPending = false; + this._runCallbacksIfReady(); + } + }); + }); } increasePendingRequestCount(): number { diff --git a/modules/angular2/test/core/testability/testability_spec.ts b/modules/angular2/test/core/testability/testability_spec.ts index dcadf4b598..6f16ad464e 100644 --- a/modules/angular2/test/core/testability/testability_spec.ts +++ b/modules/angular2/test/core/testability/testability_spec.ts @@ -14,7 +14,7 @@ import { import {Testability} from 'angular2/src/core/testability/testability'; import {NgZone} from 'angular2/src/core/zone/ng_zone'; import {normalizeBlank} from 'angular2/src/core/facade/lang'; -import {PromiseWrapper} from 'angular2/src/core/facade/async'; +import {PromiseWrapper, EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async'; // Schedules a microtasks (using a resolved promise .then()) function microTask(fn: Function): void { @@ -22,22 +22,21 @@ function microTask(fn: Function): void { } class MockNgZone extends NgZone { - _onTurnStart: () => void; - _onEventDone: () => void; + _onTurnStartStream: EventEmitter; + get onTurnStart() { return this._onTurnStartStream; } - constructor() { super({enableLongStackTrace: false}); } + _onEventDoneStream: EventEmitter; + get onEventDone() { return this._onEventDoneStream; } - start(): void { this._onTurnStart(); } - - finish(): void { this._onEventDone(); } - - overrideOnTurnStart(onTurnStartFn: Function): void { - this._onTurnStart = normalizeBlank(onTurnStartFn); + constructor() { + super({enableLongStackTrace: false}); + this._onTurnStartStream = new EventEmitter(false); + this._onEventDoneStream = new EventEmitter(false); } - overrideOnEventDone(onEventDoneFn: Function, waitForAsync: boolean = false): void { - this._onEventDone = normalizeBlank(onEventDoneFn); - } + start(): void { ObservableWrapper.callNext(this._onTurnStartStream, null); } + + finish(): void { ObservableWrapper.callNext(this._onEventDoneStream, null); } } export function main() {