Permalink
Browse files

feat(core): update zone.js to 0.8.10 and expose the flush method (#16860

)

`flush()` can now be used from within fakeAsync tests to simulate moving
time forward until all macrotask events have been cleared from the
event queue.
  • Loading branch information...
juliemr authored and chuckjaz committed May 22, 2017
1 parent 6e41add commit 85d4c4b82e3c7d8409b8346c10f6aa8190ebbbe8
@@ -1,6 +1,6 @@
{
"name": "angular-srcs",
"version": "4.2.0-beta.0",
"version": "4.2.0-beta.1",
"dependencies": {
"@types/angularjs": {
"version": "1.5.13-alpha",
@@ -6877,7 +6877,7 @@
}
},
"zone.js": {
"version": "0.8.9"
"version": "0.8.10"
}
}
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -25,7 +25,7 @@
"reflect-metadata": "^0.1.3",
"rxjs": "^5.0.1",
"typescript": "^2.3.2",
"zone.js": "^0.8.9"
"zone.js": "^0.8.10"
},
"optionalDependencies": {
"fsevents": "^1.0.14"
@@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {discardPeriodicTasks, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
import {discardPeriodicTasks, fakeAsync, flush, flushMicrotasks, tick} from '@angular/core/testing';
import {Log, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
import {expect} from '@angular/platform-browser/testing/src/matchers';
@@ -261,6 +261,42 @@ export function main() {
'microtask; timer; t microtask; periodic timer; pt microtask; periodic timer; pt microtask');
clearInterval(id);
}));
it('should flush tasks', fakeAsync(() => {
let ran = false;
setTimeout(() => { ran = true; }, 10);
flush();
expect(ran).toEqual(true);
}));
it('should flush multiple tasks', fakeAsync(() => {
let ran = false;
let ran2 = false;
setTimeout(() => { ran = true; }, 10);
setTimeout(() => { ran2 = true; }, 30);
let elapsed = flush();
expect(ran).toEqual(true);
expect(ran2).toEqual(true);
expect(elapsed).toEqual(30);
}));
it('should move periodic tasks', fakeAsync(() => {
let ran = false;
let count = 0;
setInterval(() => { count++; }, 10);
setTimeout(() => { ran = true; }, 35);
let elapsed = flush();
expect(count).toEqual(3);
expect(ran).toEqual(true);
expect(elapsed).toEqual(35);
discardPeriodicTasks();
}));
});
describe('outside of the fakeAsync zone', () => {
@@ -276,6 +312,12 @@ export function main() {
}).toThrowError('The code should be running in the fakeAsync zone to call this function');
});
it('calling flush should throw', () => {
expect(() => {
flush();
}).toThrowError('The code should be running in the fakeAsync zone to call this function');
});
it('calling discardPeriodicTasks should throw', () => {
expect(() => {
discardPeriodicTasks();
@@ -115,6 +115,20 @@ export function tick(millis: number = 0): void {
_getFakeAsyncZoneSpec().tick(millis);
}
/**
* Simulates the asynchronous passage of time for the timers in the fakeAsync zone by
* draining the macrotask queue until it is empty. The returned value is the milliseconds
* of time that would have been elapsed.
*
* @param maxTurns
* @returns {number} The simulated time elapsed, in millis.
*
* @experimental
*/
export function flush(maxTurns?: number): number {
return _getFakeAsyncZoneSpec().flush(maxTurns);
}
/**
* Discard all remaining periodic tasks.
*
@@ -32,6 +32,9 @@ export declare function discardPeriodicTasks(): void;
/** @experimental */
export declare function fakeAsync(fn: Function): (...args: any[]) => any;
/** @experimental */
export declare function flush(maxTurns?: number): number;
/** @experimental */
export declare function flushMicrotasks(): void;

0 comments on commit 85d4c4b

Please sign in to comment.