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 {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 {

View File

@ -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<any>;
get onTurnStart() { return this._onTurnStartStream; }
constructor() { super({enableLongStackTrace: false}); }
_onEventDoneStream: EventEmitter<any>;
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() {