fix: remove deprecated zone API usage in testability

Closes #5084
This commit is contained in:
Yegor Jbanov 2015-11-03 18:45:55 -08:00 committed by Yegor
parent 6133f2c08b
commit 3593d85807
2 changed files with 24 additions and 19 deletions

View File

@ -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 {CONST, CONST_EXPR} from 'angular2/src/core/facade/lang';
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions'; import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
import {NgZone} from '../zone/ng_zone'; 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 */ /** @internal */
_watchAngularEvents(_ngZone: NgZone): void { _watchAngularEvents(_ngZone: NgZone): void {
_ngZone.overrideOnTurnStart(() => { this._isAngularEventPending = true; }); ObservableWrapper.subscribe(_ngZone.onTurnStart,
_ngZone.overrideOnEventDone(() => { (_) => { this._isAngularEventPending = true; });
_ngZone.runOutsideAngular(() => {
ObservableWrapper.subscribe(_ngZone.onEventDone, (_) => {
if (!_ngZone.hasPendingTimers) {
this._isAngularEventPending = false; this._isAngularEventPending = false;
this._runCallbacksIfReady(); this._runCallbacksIfReady();
}, true); }
});
});
} }
increasePendingRequestCount(): number { increasePendingRequestCount(): number {

View File

@ -14,7 +14,7 @@ import {
import {Testability} from 'angular2/src/core/testability/testability'; import {Testability} from 'angular2/src/core/testability/testability';
import {NgZone} from 'angular2/src/core/zone/ng_zone'; import {NgZone} from 'angular2/src/core/zone/ng_zone';
import {normalizeBlank} from 'angular2/src/core/facade/lang'; 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()) // Schedules a microtasks (using a resolved promise .then())
function microTask(fn: Function): void { function microTask(fn: Function): void {
@ -22,22 +22,21 @@ function microTask(fn: Function): void {
} }
class MockNgZone extends NgZone { class MockNgZone extends NgZone {
_onTurnStart: () => void; _onTurnStartStream: EventEmitter<any>;
_onEventDone: () => void; get onTurnStart() { return this._onTurnStartStream; }
constructor() { super({enableLongStackTrace: false}); } _onEventDoneStream: EventEmitter<any>;
get onEventDone() { return this._onEventDoneStream; }
start(): void { this._onTurnStart(); } constructor() {
super({enableLongStackTrace: false});
finish(): void { this._onEventDone(); } this._onTurnStartStream = new EventEmitter(false);
this._onEventDoneStream = new EventEmitter(false);
overrideOnTurnStart(onTurnStartFn: Function): void {
this._onTurnStart = normalizeBlank(onTurnStartFn);
} }
overrideOnEventDone(onEventDoneFn: Function, waitForAsync: boolean = false): void { start(): void { ObservableWrapper.callNext(this._onTurnStartStream, null); }
this._onEventDone = normalizeBlank(onEventDoneFn);
} finish(): void { ObservableWrapper.callNext(this._onEventDoneStream, null); }
} }
export function main() { export function main() {