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

Commit 66c6f97

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(fakeAsyncTest): fix #1061, fakeAsync should support setImmediate (#1062)
Closes #1062
1 parent e15d735 commit 66c6f97

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Diff for: lib/zone-spec/fake-async-test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,10 @@
425425
task.invoke, task.data['delay'],
426426
Array.prototype.slice.call((task.data as any)['args'], 2));
427427
break;
428+
case 'setImmediate':
429+
task.data['handleId'] = this._setTimeout(
430+
task.invoke, 0, Array.prototype.slice.call((task.data as any)['args'], 1));
431+
break;
428432
case 'setInterval':
429433
task.data['handleId'] = this._setInterval(
430434
task.invoke, task.data['delay'],

Diff for: test/zone-spec/fake-async-test.spec.ts

+26
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ describe('FakeAsyncTestZoneSpec', () => {
136136
});
137137
});
138138

139+
it('should run queued immediate timer on zero tick', () => {
140+
fakeAsyncTestZone.run(() => {
141+
let ran = false;
142+
setImmediate(() => {
143+
ran = true;
144+
});
145+
146+
expect(ran).toEqual(false);
147+
148+
testZoneSpec.tick();
149+
expect(ran).toEqual(true);
150+
});
151+
});
152+
139153
it('should run queued timer after sufficient clock ticks', () => {
140154
fakeAsyncTestZone.run(() => {
141155
let ran = false;
@@ -218,6 +232,18 @@ describe('FakeAsyncTestZoneSpec', () => {
218232
});
219233
});
220234

235+
it('should pass arguments to setImmediate', () => {
236+
fakeAsyncTestZone.run(() => {
237+
let value = 'genuine value';
238+
let id = setImmediate((arg1, arg2) => {
239+
value = arg1 + arg2;
240+
}, 'expected', ' value');
241+
242+
testZoneSpec.tick();
243+
expect(value).toEqual('expected value');
244+
});
245+
});
246+
221247
it('should run periodic timers', () => {
222248
fakeAsyncTestZone.run(() => {
223249
let cycles = 0;

0 commit comments

Comments
 (0)