Skip to content

Commit 661a047

Browse files
committed
fix(test): adds longer timers for NgZone and PromisePipe tests (IE11)
Closes #2055
1 parent 665ccaf commit 661a047

File tree

7 files changed

+41
-23
lines changed

7 files changed

+41
-23
lines changed

modules/angular2/src/dom/browser_adapter.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,7 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
326326
var baseUri = Uri.parse(uri);
327327
return baseUri.path;
328328
}
329+
String getUserAgent() {
330+
return window.navigator.userAgent;
331+
}
329332
}

modules/angular2/src/dom/browser_adapter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ getLocation() {
372372
getBaseHref() {
373373
return relativePath(document.baseURI);
374374
}
375+
getUserAgent(): string {
376+
return window.navigator.userAgent;
377+
}
375378
}
376379

377380
// based on urlUtils.js in AngularJS 1

modules/angular2/src/dom/dom_adapter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,5 @@ export class DomAdapter {
114114
getHistory() { throw _abstract(); }
115115
getLocation() { throw _abstract(); }
116116
getBaseHref() { throw _abstract(); }
117+
getUserAgent() { throw _abstract(); }
117118
}

modules/angular2/src/dom/html_adapter.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,7 @@ class Html5LibDomAdapter implements DomAdapter {
303303
getBaseHref() {
304304
throw 'not implemented';
305305
}
306+
String getUserAgent() {
307+
throw 'not implemented';
308+
}
306309
}

modules/angular2/src/dom/parse5_adapter.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,9 @@ export class Parse5DomAdapter extends DomAdapter {
540540
getLocation() {
541541
throw 'not implemented';
542542
}
543+
getUserAgent() {
544+
return "Fake user agent";
545+
}
543546
}
544547

545548
//TODO: build a proper list, this one is all the keys of a HTMLInputElement

modules/angular2/test/change_detection/pipes/promise_pipe_spec.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import {PromisePipe} from 'angular2/src/change_detection/pipes/promise_pipe';
55
import {WrappedValue} from 'angular2/src/change_detection/pipes/pipe';
66
import {ChangeDetectorRef} from 'angular2/src/change_detection/change_detector_ref';
77
import {PromiseWrapper, TimerWrapper} from 'angular2/src/facade/async';
8+
import {DOM} from 'angular2/src/dom/dom_adapter';
89

910
export function main() {
1011
describe("PromisePipe", () => {
1112
var message = new Object();
1213
var pipe;
1314
var completer;
1415
var ref;
16+
//adds longer timers for passing tests in IE
17+
var timer = (DOM.getUserAgent().indexOf("Trident") > -1) ? 50 : 0;
1518

1619
beforeEach(() => {
1720
completer = PromiseWrapper.completer();
@@ -43,7 +46,7 @@ export function main() {
4346
TimerWrapper.setTimeout(() => {
4447
expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message));
4548
async.done();
46-
}, 0)
49+
}, timer)
4750
}));
4851

4952
it("should return unwrapped value when nothing has changed since the last call",
@@ -55,7 +58,7 @@ export function main() {
5558
pipe.transform(completer.promise);
5659
expect(pipe.transform(completer.promise)).toBe(message);
5760
async.done();
58-
}, 0)
61+
}, timer)
5962
}));
6063

6164
it("should dispose of the existing subscription when subscribing to a new promise",
@@ -71,7 +74,7 @@ export function main() {
7174
TimerWrapper.setTimeout(() => {
7275
expect(pipe.transform(newCompleter.promise)).toBe(null);
7376
async.done();
74-
}, 0)
77+
}, timer)
7578
}));
7679

7780
it("should request a change detection check upon receiving a new value",
@@ -82,7 +85,7 @@ export function main() {
8285
TimerWrapper.setTimeout(() => {
8386
expect(ref.spy('requestCheck')).toHaveBeenCalled();
8487
async.done();
85-
}, 0)
88+
}, timer)
8689
}));
8790

8891
describe("onDestroy", () => {
@@ -101,7 +104,7 @@ export function main() {
101104
pipe.onDestroy();
102105
expect(pipe.transform(completer.promise)).toBe(null);
103106
async.done();
104-
}, 0);
107+
}, timer);
105108
}));
106109
});
107110
});

modules/angular2/test/core/zone/ng_zone_spec.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ import {
1616
import {PromiseWrapper, TimerWrapper} from 'angular2/src/facade/async';
1717
import {ListWrapper} from 'angular2/src/facade/collection';
1818
import {BaseException} from 'angular2/src/facade/lang';
19+
import {DOM} from 'angular2/src/dom/dom_adapter';
1920

2021
import {NgZone} from 'angular2/src/core/zone/ng_zone';
2122

23+
var isIE = DOM.getUserAgent().indexOf("Trident") > -1;
2224
// Schedules a macrotask (using a timer)
23-
function macroTask(fn: Function): void {
24-
_zone.runOutsideAngular(() => TimerWrapper.setTimeout(fn, 1));
25+
function macroTask(fn: Function, timer = 1): void {
26+
//adds longer timers for passing tests in IE
27+
_zone.runOutsideAngular(() => TimerWrapper.setTimeout(fn, isIE ? timer : 1));
2528
}
2629

2730
// Schedules a microtasks (using a resolved promise .then())
@@ -192,7 +195,7 @@ function commonTests() {
192195
// The microtask (async) is executed after the macrotask (run)
193196
expect(_log.result()).toEqual('onTurnStart; run start; run end; async; onTurnDone');
194197
async.done();
195-
});
198+
}, 50);
196199
}));
197200

198201
it('should not run onTurnStart and onTurnDone for nested Zone.run',
@@ -211,7 +214,7 @@ function commonTests() {
211214
macroTask(() => {
212215
expect(_log.result()).toEqual('onTurnStart; start run; nested run; end run; nested run microtask; onTurnDone');
213216
async.done();
214-
});
217+
}, 50);
215218
}));
216219

217220
it('should call onTurnStart and onTurnDone before and after each top-level run',
@@ -256,7 +259,7 @@ function commonTests() {
256259
macroTask(() => {
257260
expect(_log.result()).toEqual('onTurnStart; run start; onTurnDone; onTurnStart; a then; b then; onTurnDone');
258261
async.done();
259-
});
262+
}, 50);
260263
}));
261264

262265
it('should run a function outside of the angular zone', inject([AsyncTestCompleter], (async) => {
@@ -303,7 +306,7 @@ function commonTests() {
303306
'onTurnStart; executedMicrotask; onTurnDone'
304307
);
305308
async.done();
306-
});
309+
}, 50);
307310
}));
308311

309312
it('should call onTurnStart before executing a microtask scheduled in onTurnDone as well as ' +
@@ -334,7 +337,7 @@ function commonTests() {
334337
'onTurnStart; executedMicrotask; onTurnDone(begin); onTurnDone(end)'
335338
);
336339
async.done();
337-
});
340+
}, 50);
338341
}));
339342

340343
it('should call onTurnStart and onTurnDone for a scheduleMicrotask in onTurnDone triggered by ' +
@@ -369,8 +372,7 @@ function commonTests() {
369372
'onTurnStart; onTurnDone(executeMicrotask); onTurnDone(begin); onTurnDone(end)'
370373
);
371374
async.done();
372-
373-
});
375+
}, 50);
374376
}));
375377

376378
it('should execute promises scheduled in onTurnStart before promises scheduled in run',
@@ -426,7 +428,7 @@ function commonTests() {
426428
'onTurnStart(begin); onTurnStart(end); onTurnDone(executePromise); onTurnDone(begin); onTurnDone(end)'
427429
);
428430
async.done();
429-
});
431+
}, 50);
430432
}));
431433

432434
it('should call onTurnStart and onTurnDone before and after each turn, respectively',
@@ -447,14 +449,14 @@ function commonTests() {
447449
_zone.run(() => {
448450
completerA.resolve(null);
449451
});
450-
});
452+
}, 10);
451453

452454

453455
macroTask(() => {
454456
_zone.run(() => {
455457
completerB.resolve(null);
456458
});
457-
});
459+
}, 30);
458460

459461
macroTask(() => {
460462
expect(_log.result()).toEqual(
@@ -465,7 +467,7 @@ function commonTests() {
465467
// Third VM turn
466468
'onTurnStart; b then; onTurnDone');
467469
async.done();
468-
});
470+
}, 60);
469471
}));
470472

471473
it('should call onTurnStart and onTurnDone before and after (respectively) all turns in a chain',
@@ -484,7 +486,7 @@ function commonTests() {
484486
macroTask(() => {
485487
expect(_log.result()).toEqual('onTurnStart; run start; run end; async1; async2; onTurnDone');
486488
async.done();
487-
});
489+
}, 50);
488490
}));
489491

490492
it('should call onTurnStart and onTurnDone for promises created outside of run body',
@@ -505,7 +507,7 @@ function commonTests() {
505507
macroTask(() => {
506508
expect(_log.result()).toEqual('onTurnStart; zone run; onTurnDone; onTurnStart; promise then; onTurnDone');
507509
async.done();
508-
});
510+
}, 50);
509511
}));
510512
});
511513

@@ -541,7 +543,7 @@ function commonTests() {
541543
expect(_errors.length).toBe(1);
542544
expect(_errors[0]).toEqual(exception);
543545
async.done();
544-
});
546+
}, 50);
545547
}));
546548

547549
it('should call onError when onTurnDone throws and the zone is sync',
@@ -561,7 +563,7 @@ function commonTests() {
561563
expect(_errors.length).toBe(1);
562564
expect(_errors[0]).toEqual(exception);
563565
async.done();
564-
});
566+
}, 50);
565567
}));
566568

567569
it('should call onError when onTurnDone throws and the zone is async',
@@ -587,7 +589,7 @@ function commonTests() {
587589
expect(_errors.length).toBe(1);
588590
expect(_errors[0]).toEqual(exception);
589591
async.done();
590-
});
592+
}, 50);
591593
}));
592594
});
593595
}

0 commit comments

Comments
 (0)