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

Commit eefe983

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(testing): fix #1032, fakeAsync should pass parameters correctly (#1033)
1 parent ebd348c commit eefe983

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/zone-spec/fake-async-test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294
this._scheduler.removeScheduledFunctionWithId(id);
295295
}
296296

297-
private _setInterval(fn: Function, interval: number, ...args: any[]): number {
297+
private _setInterval(fn: Function, interval: number, args: any[]): number {
298298
let id = this._scheduler.nextId;
299299
let completers = {onSuccess: null as Function, onError: this._dequeuePeriodicTimer(id)};
300300
let cb = this._fnAndFlush(fn, completers);
@@ -410,11 +410,11 @@
410410
switch (task.source) {
411411
case 'setTimeout':
412412
task.data['handleId'] =
413-
this._setTimeout(task.invoke, task.data['delay'], (task.data as any)['args']);
413+
this._setTimeout(task.invoke, task.data['delay'], Array.prototype.slice.call((task.data as any)['args'], 2));
414414
break;
415415
case 'setInterval':
416416
task.data['handleId'] =
417-
this._setInterval(task.invoke, task.data['delay'], (task.data as any)['args']);
417+
this._setInterval(task.invoke, task.data['delay'], Array.prototype.slice.call((task.data as any)['args'], 2));
418418
break;
419419
case 'XMLHttpRequest.send':
420420
throw new Error(

test/zone-spec/fake-async-test.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@ describe('FakeAsyncTestZoneSpec', () => {
206206
});
207207
});
208208

209+
it('should pass arguments to times', () => {
210+
fakeAsyncTestZone.run(() => {
211+
let value = 'genuine value';
212+
let id = setTimeout((arg1, arg2) => {
213+
value = arg1 + arg2;
214+
}, 0, 'expected', ' value');
215+
216+
testZoneSpec.tick();
217+
expect(value).toEqual('expected value');
218+
});
219+
});
220+
209221
it('should run periodic timers', () => {
210222
fakeAsyncTestZone.run(() => {
211223
let cycles = 0;
@@ -227,6 +239,18 @@ describe('FakeAsyncTestZoneSpec', () => {
227239
});
228240
});
229241

242+
it('should pass arguments to periodic timers', () => {
243+
fakeAsyncTestZone.run(() => {
244+
let value = 'genuine value';
245+
let id = setInterval((arg1, arg2) => {
246+
value = arg1 + arg2;
247+
}, 10, 'expected', ' value');
248+
249+
testZoneSpec.tick(10);
250+
expect(value).toEqual('expected value');
251+
});
252+
});
253+
230254
it('should not run cancelled periodic timer', () => {
231255
fakeAsyncTestZone.run(() => {
232256
let ran = false;

0 commit comments

Comments
 (0)