Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Ensure FakeAsyncTestZoneSpec tick always doTick #1099

Merged
merged 1 commit into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/zone-spec/fake-async-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ class Scheduler {
}
}
}
lastCurrentTime = this._currentTime;
this._currentTime = finalTime;
if (doTick) {
doTick(this._currentTime - lastCurrentTime);
}
}

flush(limit = 20, flushPeriodic = false, doTick?: (elapsed: number) => void): number {
Expand Down
19 changes: 19 additions & 0 deletions test/zone-spec/fake-async-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,25 @@ describe('FakeAsyncTestZoneSpec', () => {
});
});

it('should run doTick callback even if no work ran', () => {
fakeAsyncTestZone.run(() => {
let totalElapsed = 0;
function doTick(elapsed: number) {
totalElapsed += elapsed;
}
setTimeout(() => {}, 10);

testZoneSpec.tick(6, doTick);
expect(totalElapsed).toEqual(6);

testZoneSpec.tick(6, doTick);
expect(totalElapsed).toEqual(12);

testZoneSpec.tick(6, doTick);
expect(totalElapsed).toEqual(18);
});
});

it('should run queued timer created by timer callback', () => {
fakeAsyncTestZone.run(() => {
let counter = 0;
Expand Down