chore: upgrade to new Zone.js API v0.6.2
BREAKING CHANGE Removed deprecated API from NgZone - `NgZone.overrideOnTurnStart` - `NgZone.overrideOnTurnDone` - `NgZone.overrideOnEventDone` - `NgZone.overrideOnErrorHandler` Rename NgZone API - `NgZone.onTurnStart` => `NgZone.onUnstable` - `NgZone.onTurnDone` => `NgZone.onMicrotaskEmpty` - `NgZone.onEventDone` => `NgZone.onStable` Closes #7345
This commit is contained in:

committed by
Miško Hevery

parent
f9fb72fb0e
commit
310620fd12
@ -14,36 +14,43 @@ import {
|
||||
} from 'angular2/testing_internal';
|
||||
import {Testability} from 'angular2/src/core/testability/testability';
|
||||
import {NgZone} from 'angular2/src/core/zone/ng_zone';
|
||||
import {normalizeBlank} from 'angular2/src/facade/lang';
|
||||
import {normalizeBlank, scheduleMicroTask} from 'angular2/src/facade/lang';
|
||||
import {PromiseWrapper, EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
|
||||
|
||||
// Schedules a microtasks (using a resolved promise .then())
|
||||
function microTask(fn: Function): void {
|
||||
PromiseWrapper.resolve(null).then((_) => { fn(); });
|
||||
scheduleMicroTask(() => {
|
||||
// We do double dispatch so that we can wait for scheduleMicrotas in the Testability when
|
||||
// NgZone becomes stable.
|
||||
scheduleMicroTask(fn);
|
||||
});
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
class MockNgZone extends NgZone {
|
||||
_onTurnStartStream: EventEmitter<any>;
|
||||
get onTurnStart() { return this._onTurnStartStream; }
|
||||
_onUnstableStream: EventEmitter<any>;
|
||||
get onUnstable() { return this._onUnstableStream; }
|
||||
|
||||
_onEventDoneStream: EventEmitter<any>;
|
||||
get onEventDone() { return this._onEventDoneStream; }
|
||||
_onStableStream: EventEmitter<any>;
|
||||
get onStable() { return this._onStableStream; }
|
||||
|
||||
constructor() {
|
||||
super({enableLongStackTrace: false});
|
||||
this._onTurnStartStream = new EventEmitter(false);
|
||||
this._onEventDoneStream = new EventEmitter(false);
|
||||
this._onUnstableStream = new EventEmitter(false);
|
||||
this._onStableStream = new EventEmitter(false);
|
||||
}
|
||||
|
||||
start(): void { ObservableWrapper.callEmit(this._onTurnStartStream, null); }
|
||||
unstable(): void { ObservableWrapper.callEmit(this._onUnstableStream, null); }
|
||||
|
||||
finish(): void { ObservableWrapper.callEmit(this._onEventDoneStream, null); }
|
||||
stable(): void { ObservableWrapper.callEmit(this._onStableStream, null); }
|
||||
}
|
||||
|
||||
export function main() {
|
||||
describe('Testability', () => {
|
||||
var testability, execute, execute2, ngZone;
|
||||
var testability: Testability;
|
||||
var execute: any;
|
||||
var execute2: any;
|
||||
var ngZone: MockNgZone;
|
||||
|
||||
beforeEach(() => {
|
||||
ngZone = new MockNgZone();
|
||||
@ -142,13 +149,10 @@ export function main() {
|
||||
});
|
||||
|
||||
describe('NgZone callback logic', () => {
|
||||
it('should start being ready',
|
||||
() => { expect(testability.isAngularEventPending()).toEqual(false); });
|
||||
|
||||
it('should fire whenstable callback if event is already finished',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
ngZone.start();
|
||||
ngZone.finish();
|
||||
ngZone.unstable();
|
||||
ngZone.stable();
|
||||
testability.whenStable(execute);
|
||||
|
||||
microTask(() => {
|
||||
@ -158,8 +162,8 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should not fire whenstable callbacks synchronously if event is already finished', () => {
|
||||
ngZone.start();
|
||||
ngZone.finish();
|
||||
ngZone.unstable();
|
||||
ngZone.stable();
|
||||
testability.whenStable(execute);
|
||||
|
||||
expect(execute).not.toHaveBeenCalled();
|
||||
@ -167,12 +171,12 @@ export function main() {
|
||||
|
||||
it('should fire whenstable callback when event finishes',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
ngZone.start();
|
||||
ngZone.unstable();
|
||||
testability.whenStable(execute);
|
||||
|
||||
microTask(() => {
|
||||
expect(execute).not.toHaveBeenCalled();
|
||||
ngZone.finish();
|
||||
ngZone.stable();
|
||||
|
||||
microTask(() => {
|
||||
expect(execute).toHaveBeenCalled();
|
||||
@ -182,16 +186,16 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should not fire whenstable callbacks synchronously when event finishes', () => {
|
||||
ngZone.start();
|
||||
ngZone.unstable();
|
||||
testability.whenStable(execute);
|
||||
ngZone.finish();
|
||||
ngZone.stable();
|
||||
|
||||
expect(execute).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not fire whenstable callback when event did not finish',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
ngZone.start();
|
||||
ngZone.unstable();
|
||||
testability.increasePendingRequestCount();
|
||||
testability.whenStable(execute);
|
||||
|
||||
@ -201,7 +205,7 @@ export function main() {
|
||||
|
||||
microTask(() => {
|
||||
expect(execute).not.toHaveBeenCalled();
|
||||
ngZone.finish();
|
||||
ngZone.stable();
|
||||
|
||||
microTask(() => {
|
||||
expect(execute).toHaveBeenCalled();
|
||||
@ -213,14 +217,14 @@ export function main() {
|
||||
|
||||
it('should not fire whenstable callback when there are pending counts',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
ngZone.start();
|
||||
ngZone.unstable();
|
||||
testability.increasePendingRequestCount();
|
||||
testability.increasePendingRequestCount();
|
||||
testability.whenStable(execute);
|
||||
|
||||
microTask(() => {
|
||||
expect(execute).not.toHaveBeenCalled();
|
||||
ngZone.finish();
|
||||
ngZone.stable();
|
||||
|
||||
microTask(() => {
|
||||
expect(execute).not.toHaveBeenCalled();
|
||||
@ -241,8 +245,8 @@ export function main() {
|
||||
|
||||
it('should fire whenstable callback with didWork if event is already finished',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
ngZone.start();
|
||||
ngZone.finish();
|
||||
ngZone.unstable();
|
||||
ngZone.stable();
|
||||
testability.whenStable(execute);
|
||||
|
||||
microTask(() => {
|
||||
@ -258,11 +262,11 @@ export function main() {
|
||||
|
||||
it('should fire whenstable callback with didwork when event finishes',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
ngZone.start();
|
||||
ngZone.unstable();
|
||||
testability.whenStable(execute);
|
||||
|
||||
microTask(() => {
|
||||
ngZone.finish();
|
||||
ngZone.stable();
|
||||
|
||||
microTask(() => {
|
||||
expect(execute).toHaveBeenCalledWith(true);
|
||||
|
Reference in New Issue
Block a user