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

Commit

Permalink
fix(testing): fix #1032, fakeAsync should pass parameters correctly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion authored and mhevery committed Feb 27, 2018
1 parent ebd348c commit eefe983
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/zone-spec/fake-async-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
this._scheduler.removeScheduledFunctionWithId(id);
}

private _setInterval(fn: Function, interval: number, ...args: any[]): number {
private _setInterval(fn: Function, interval: number, args: any[]): number {
let id = this._scheduler.nextId;
let completers = {onSuccess: null as Function, onError: this._dequeuePeriodicTimer(id)};
let cb = this._fnAndFlush(fn, completers);
Expand Down Expand Up @@ -410,11 +410,11 @@
switch (task.source) {
case 'setTimeout':
task.data['handleId'] =
this._setTimeout(task.invoke, task.data['delay'], (task.data as any)['args']);
this._setTimeout(task.invoke, task.data['delay'], Array.prototype.slice.call((task.data as any)['args'], 2));
break;
case 'setInterval':
task.data['handleId'] =
this._setInterval(task.invoke, task.data['delay'], (task.data as any)['args']);
this._setInterval(task.invoke, task.data['delay'], Array.prototype.slice.call((task.data as any)['args'], 2));
break;
case 'XMLHttpRequest.send':
throw new Error(
Expand Down
24 changes: 24 additions & 0 deletions test/zone-spec/fake-async-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ describe('FakeAsyncTestZoneSpec', () => {
});
});

it('should pass arguments to times', () => {
fakeAsyncTestZone.run(() => {
let value = 'genuine value';
let id = setTimeout((arg1, arg2) => {
value = arg1 + arg2;
}, 0, 'expected', ' value');

testZoneSpec.tick();
expect(value).toEqual('expected value');
});
});

it('should run periodic timers', () => {
fakeAsyncTestZone.run(() => {
let cycles = 0;
Expand All @@ -227,6 +239,18 @@ describe('FakeAsyncTestZoneSpec', () => {
});
});

it('should pass arguments to periodic timers', () => {
fakeAsyncTestZone.run(() => {
let value = 'genuine value';
let id = setInterval((arg1, arg2) => {
value = arg1 + arg2;
}, 10, 'expected', ' value');

testZoneSpec.tick(10);
expect(value).toEqual('expected value');
});
});

it('should not run cancelled periodic timer', () => {
fakeAsyncTestZone.run(() => {
let ran = false;
Expand Down

0 comments on commit eefe983

Please sign in to comment.