fix(test): adds longer timers for NgZone and PromisePipe tests (IE11)

Closes #2055
This commit is contained in:
Marc Laval 2015-05-21 11:54:31 +02:00
parent 665ccafd73
commit 661a04798e
7 changed files with 41 additions and 23 deletions

View File

@ -326,4 +326,7 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
var baseUri = Uri.parse(uri); var baseUri = Uri.parse(uri);
return baseUri.path; return baseUri.path;
} }
String getUserAgent() {
return window.navigator.userAgent;
}
} }

View File

@ -372,6 +372,9 @@ getLocation() {
getBaseHref() { getBaseHref() {
return relativePath(document.baseURI); return relativePath(document.baseURI);
} }
getUserAgent(): string {
return window.navigator.userAgent;
}
} }
// based on urlUtils.js in AngularJS 1 // based on urlUtils.js in AngularJS 1

View File

@ -114,4 +114,5 @@ export class DomAdapter {
getHistory() { throw _abstract(); } getHistory() { throw _abstract(); }
getLocation() { throw _abstract(); } getLocation() { throw _abstract(); }
getBaseHref() { throw _abstract(); } getBaseHref() { throw _abstract(); }
getUserAgent() { throw _abstract(); }
} }

View File

@ -303,4 +303,7 @@ class Html5LibDomAdapter implements DomAdapter {
getBaseHref() { getBaseHref() {
throw 'not implemented'; throw 'not implemented';
} }
String getUserAgent() {
throw 'not implemented';
}
} }

View File

@ -540,6 +540,9 @@ export class Parse5DomAdapter extends DomAdapter {
getLocation() { getLocation() {
throw 'not implemented'; throw 'not implemented';
} }
getUserAgent() {
return "Fake user agent";
}
} }
//TODO: build a proper list, this one is all the keys of a HTMLInputElement //TODO: build a proper list, this one is all the keys of a HTMLInputElement

View File

@ -5,6 +5,7 @@ import {PromisePipe} from 'angular2/src/change_detection/pipes/promise_pipe';
import {WrappedValue} from 'angular2/src/change_detection/pipes/pipe'; import {WrappedValue} from 'angular2/src/change_detection/pipes/pipe';
import {ChangeDetectorRef} from 'angular2/src/change_detection/change_detector_ref'; import {ChangeDetectorRef} from 'angular2/src/change_detection/change_detector_ref';
import {PromiseWrapper, TimerWrapper} from 'angular2/src/facade/async'; import {PromiseWrapper, TimerWrapper} from 'angular2/src/facade/async';
import {DOM} from 'angular2/src/dom/dom_adapter';
export function main() { export function main() {
describe("PromisePipe", () => { describe("PromisePipe", () => {
@ -12,6 +13,8 @@ export function main() {
var pipe; var pipe;
var completer; var completer;
var ref; var ref;
//adds longer timers for passing tests in IE
var timer = (DOM.getUserAgent().indexOf("Trident") > -1) ? 50 : 0;
beforeEach(() => { beforeEach(() => {
completer = PromiseWrapper.completer(); completer = PromiseWrapper.completer();
@ -43,7 +46,7 @@ export function main() {
TimerWrapper.setTimeout(() => { TimerWrapper.setTimeout(() => {
expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message)); expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message));
async.done(); async.done();
}, 0) }, timer)
})); }));
it("should return unwrapped value when nothing has changed since the last call", it("should return unwrapped value when nothing has changed since the last call",
@ -55,7 +58,7 @@ export function main() {
pipe.transform(completer.promise); pipe.transform(completer.promise);
expect(pipe.transform(completer.promise)).toBe(message); expect(pipe.transform(completer.promise)).toBe(message);
async.done(); async.done();
}, 0) }, timer)
})); }));
it("should dispose of the existing subscription when subscribing to a new promise", it("should dispose of the existing subscription when subscribing to a new promise",
@ -71,7 +74,7 @@ export function main() {
TimerWrapper.setTimeout(() => { TimerWrapper.setTimeout(() => {
expect(pipe.transform(newCompleter.promise)).toBe(null); expect(pipe.transform(newCompleter.promise)).toBe(null);
async.done(); async.done();
}, 0) }, timer)
})); }));
it("should request a change detection check upon receiving a new value", it("should request a change detection check upon receiving a new value",
@ -82,7 +85,7 @@ export function main() {
TimerWrapper.setTimeout(() => { TimerWrapper.setTimeout(() => {
expect(ref.spy('requestCheck')).toHaveBeenCalled(); expect(ref.spy('requestCheck')).toHaveBeenCalled();
async.done(); async.done();
}, 0) }, timer)
})); }));
describe("onDestroy", () => { describe("onDestroy", () => {
@ -101,7 +104,7 @@ export function main() {
pipe.onDestroy(); pipe.onDestroy();
expect(pipe.transform(completer.promise)).toBe(null); expect(pipe.transform(completer.promise)).toBe(null);
async.done(); async.done();
}, 0); }, timer);
})); }));
}); });
}); });

View File

@ -16,12 +16,15 @@ import {
import {PromiseWrapper, TimerWrapper} from 'angular2/src/facade/async'; import {PromiseWrapper, TimerWrapper} from 'angular2/src/facade/async';
import {ListWrapper} from 'angular2/src/facade/collection'; import {ListWrapper} from 'angular2/src/facade/collection';
import {BaseException} from 'angular2/src/facade/lang'; import {BaseException} from 'angular2/src/facade/lang';
import {DOM} from 'angular2/src/dom/dom_adapter';
import {NgZone} from 'angular2/src/core/zone/ng_zone'; import {NgZone} from 'angular2/src/core/zone/ng_zone';
var isIE = DOM.getUserAgent().indexOf("Trident") > -1;
// Schedules a macrotask (using a timer) // Schedules a macrotask (using a timer)
function macroTask(fn: Function): void { function macroTask(fn: Function, timer = 1): void {
_zone.runOutsideAngular(() => TimerWrapper.setTimeout(fn, 1)); //adds longer timers for passing tests in IE
_zone.runOutsideAngular(() => TimerWrapper.setTimeout(fn, isIE ? timer : 1));
} }
// Schedules a microtasks (using a resolved promise .then()) // Schedules a microtasks (using a resolved promise .then())
@ -192,7 +195,7 @@ function commonTests() {
// The microtask (async) is executed after the macrotask (run) // The microtask (async) is executed after the macrotask (run)
expect(_log.result()).toEqual('onTurnStart; run start; run end; async; onTurnDone'); expect(_log.result()).toEqual('onTurnStart; run start; run end; async; onTurnDone');
async.done(); async.done();
}); }, 50);
})); }));
it('should not run onTurnStart and onTurnDone for nested Zone.run', it('should not run onTurnStart and onTurnDone for nested Zone.run',
@ -211,7 +214,7 @@ function commonTests() {
macroTask(() => { macroTask(() => {
expect(_log.result()).toEqual('onTurnStart; start run; nested run; end run; nested run microtask; onTurnDone'); expect(_log.result()).toEqual('onTurnStart; start run; nested run; end run; nested run microtask; onTurnDone');
async.done(); async.done();
}); }, 50);
})); }));
it('should call onTurnStart and onTurnDone before and after each top-level run', it('should call onTurnStart and onTurnDone before and after each top-level run',
@ -256,7 +259,7 @@ function commonTests() {
macroTask(() => { macroTask(() => {
expect(_log.result()).toEqual('onTurnStart; run start; onTurnDone; onTurnStart; a then; b then; onTurnDone'); expect(_log.result()).toEqual('onTurnStart; run start; onTurnDone; onTurnStart; a then; b then; onTurnDone');
async.done(); async.done();
}); }, 50);
})); }));
it('should run a function outside of the angular zone', inject([AsyncTestCompleter], (async) => { it('should run a function outside of the angular zone', inject([AsyncTestCompleter], (async) => {
@ -303,7 +306,7 @@ function commonTests() {
'onTurnStart; executedMicrotask; onTurnDone' 'onTurnStart; executedMicrotask; onTurnDone'
); );
async.done(); async.done();
}); }, 50);
})); }));
it('should call onTurnStart before executing a microtask scheduled in onTurnDone as well as ' + it('should call onTurnStart before executing a microtask scheduled in onTurnDone as well as ' +
@ -334,7 +337,7 @@ function commonTests() {
'onTurnStart; executedMicrotask; onTurnDone(begin); onTurnDone(end)' 'onTurnStart; executedMicrotask; onTurnDone(begin); onTurnDone(end)'
); );
async.done(); async.done();
}); }, 50);
})); }));
it('should call onTurnStart and onTurnDone for a scheduleMicrotask in onTurnDone triggered by ' + it('should call onTurnStart and onTurnDone for a scheduleMicrotask in onTurnDone triggered by ' +
@ -369,8 +372,7 @@ function commonTests() {
'onTurnStart; onTurnDone(executeMicrotask); onTurnDone(begin); onTurnDone(end)' 'onTurnStart; onTurnDone(executeMicrotask); onTurnDone(begin); onTurnDone(end)'
); );
async.done(); async.done();
}, 50);
});
})); }));
it('should execute promises scheduled in onTurnStart before promises scheduled in run', it('should execute promises scheduled in onTurnStart before promises scheduled in run',
@ -426,7 +428,7 @@ function commonTests() {
'onTurnStart(begin); onTurnStart(end); onTurnDone(executePromise); onTurnDone(begin); onTurnDone(end)' 'onTurnStart(begin); onTurnStart(end); onTurnDone(executePromise); onTurnDone(begin); onTurnDone(end)'
); );
async.done(); async.done();
}); }, 50);
})); }));
it('should call onTurnStart and onTurnDone before and after each turn, respectively', it('should call onTurnStart and onTurnDone before and after each turn, respectively',
@ -447,14 +449,14 @@ function commonTests() {
_zone.run(() => { _zone.run(() => {
completerA.resolve(null); completerA.resolve(null);
}); });
}); }, 10);
macroTask(() => { macroTask(() => {
_zone.run(() => { _zone.run(() => {
completerB.resolve(null); completerB.resolve(null);
}); });
}); }, 30);
macroTask(() => { macroTask(() => {
expect(_log.result()).toEqual( expect(_log.result()).toEqual(
@ -465,7 +467,7 @@ function commonTests() {
// Third VM turn // Third VM turn
'onTurnStart; b then; onTurnDone'); 'onTurnStart; b then; onTurnDone');
async.done(); async.done();
}); }, 60);
})); }));
it('should call onTurnStart and onTurnDone before and after (respectively) all turns in a chain', it('should call onTurnStart and onTurnDone before and after (respectively) all turns in a chain',
@ -484,7 +486,7 @@ function commonTests() {
macroTask(() => { macroTask(() => {
expect(_log.result()).toEqual('onTurnStart; run start; run end; async1; async2; onTurnDone'); expect(_log.result()).toEqual('onTurnStart; run start; run end; async1; async2; onTurnDone');
async.done(); async.done();
}); }, 50);
})); }));
it('should call onTurnStart and onTurnDone for promises created outside of run body', it('should call onTurnStart and onTurnDone for promises created outside of run body',
@ -505,7 +507,7 @@ function commonTests() {
macroTask(() => { macroTask(() => {
expect(_log.result()).toEqual('onTurnStart; zone run; onTurnDone; onTurnStart; promise then; onTurnDone'); expect(_log.result()).toEqual('onTurnStart; zone run; onTurnDone; onTurnStart; promise then; onTurnDone');
async.done(); async.done();
}); }, 50);
})); }));
}); });
@ -541,7 +543,7 @@ function commonTests() {
expect(_errors.length).toBe(1); expect(_errors.length).toBe(1);
expect(_errors[0]).toEqual(exception); expect(_errors[0]).toEqual(exception);
async.done(); async.done();
}); }, 50);
})); }));
it('should call onError when onTurnDone throws and the zone is sync', it('should call onError when onTurnDone throws and the zone is sync',
@ -561,7 +563,7 @@ function commonTests() {
expect(_errors.length).toBe(1); expect(_errors.length).toBe(1);
expect(_errors[0]).toEqual(exception); expect(_errors[0]).toEqual(exception);
async.done(); async.done();
}); }, 50);
})); }));
it('should call onError when onTurnDone throws and the zone is async', it('should call onError when onTurnDone throws and the zone is async',
@ -587,7 +589,7 @@ function commonTests() {
expect(_errors.length).toBe(1); expect(_errors.length).toBe(1);
expect(_errors[0]).toEqual(exception); expect(_errors[0]).toEqual(exception);
async.done(); async.done();
}); }, 50);
})); }));
}); });
} }