diff --git a/types/sinon/index.d.ts b/types/sinon/index.d.ts index e07a69eb74..e45476a7ee 100644 --- a/types/sinon/index.d.ts +++ b/types/sinon/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Sinon 7.0 +// Type definitions for Sinon 7.5 // Project: https://sinonjs.org // Definitions by: William Sears // Jonathan Little @@ -729,16 +729,25 @@ declare namespace Sinon { interface SinonFakeTimers { now: number; + loopLimit: number; setTimeout(callback: (...args: any[]) => void, timeout: number, ...args: any[]): SinonTimerId; clearTimeout(id: SinonTimerId): void; + setInterval(callback: (...args: any[]) => void, timeout: number, ...args: any[]): SinonTimerId; clearInterval(id: SinonTimerId): void; + setImmediate(callback: (...args: any[]) => void, ...args: any[]): SinonTimerId; clearImmediate(id: SinonTimerId): void; - requestAnimationFrame(callback: (...args: any[]) => void): number; - cancelAnimationFrame(id: number): void; - nextTick(callback: () => void): void; + + requestAnimationFrame(callback: (time: number) => void): SinonTimerId; + cancelAnimationFrame(id: SinonTimerId): void; + + nextTick(callback: (...args: any[]) => void, ...args: any[]): void; + queueMicrotask(callback: () => void): void; + + requestIdleCallback(func: (...args: any[]) => void, timeout?: number, ...args: any[]): SinonTimerId; + cancelIdleCallback(timerId: SinonTimerId): void; /** * Tick the clock ahead time milliseconds. @@ -748,20 +757,20 @@ declare namespace Sinon { * time may be negative, which causes the clock to change but won’t fire any callbacks. * @param ms */ - tick(ms: number | string): void; + tick(ms: number | string): number; /** * Advances the clock to the the moment of the first scheduled timer, firing it. */ - next(): void; + next(): number; /** * This runs all pending timers until there are none remaining. If new timers are added while it is executing they will be run as well. * This makes it easier to run asynchronous tests to completion without worrying about the number of timers they use, or the delays in those timers. */ - runAll(): void; - runToLast(): void; + runAll(): number; + runToLast(): number; reset(): void; runMicrotasks(): void; - runToFrame(): void; + runToFrame(): number; Date(): Date; Date(year: number): Date; @@ -791,6 +800,8 @@ declare namespace Sinon { * @param now The new 'now' as a JavaScript Date */ setSystemTime(date: Date): void; + + countTimers(): number; } interface SinonFakeTimersConfig { diff --git a/types/sinon/ts3.1/index.d.ts b/types/sinon/ts3.1/index.d.ts index 6604784b20..0248f4488b 100644 --- a/types/sinon/ts3.1/index.d.ts +++ b/types/sinon/ts3.1/index.d.ts @@ -757,27 +757,39 @@ declare namespace Sinon { interface SinonFakeTimers { now: number; + loopLimit: number; - setTimeout( - callback: (...args: any[]) => void, + setTimeout( + callback: (...args: TArgs) => void, timeout: number, - ...args: any[] + ...args: TArgs ): SinonTimerId; clearTimeout(id: SinonTimerId): void; - setInterval( - callback: (...args: any[]) => void, + + setInterval( + callback: (...args: TArgs) => void, timeout: number, - ...args: any[] + ...args: TArgs ): SinonTimerId; clearInterval(id: SinonTimerId): void; - setImmediate( - callback: (...args: any[]) => void, - ...args: any[] + + setImmediate( + callback: (...args: TArgs) => void, + ...args: TArgs ): SinonTimerId; clearImmediate(id: SinonTimerId): void; - requestAnimationFrame(callback: (...args: any[]) => void): number; - cancelAnimationFrame(id: number): void; - nextTick(callback: () => void): void; + + requestAnimationFrame(callback: (time: number) => void): SinonTimerId; + cancelAnimationFrame(id: SinonTimerId): void; + + nextTick( + callback: (...args: TArgs) => void, + ...args: TArgs): void; + queueMicrotask(callback: () => void): void; + + requestIdleCallback(func: (...args: TArgs) => void, timeout?: number, ...args: + TArgs): SinonTimerId; + cancelIdleCallback(timerId: SinonTimerId): void; /** * Tick the clock ahead time milliseconds. @@ -787,20 +799,20 @@ declare namespace Sinon { * time may be negative, which causes the clock to change but won’t fire any callbacks. * @param ms */ - tick(ms: number | string): void; + tick(ms: number | string): number; /** * Advances the clock to the the moment of the first scheduled timer, firing it. */ - next(): void; + next(): number; /** * This runs all pending timers until there are none remaining. If new timers are added while it is executing they will be run as well. * This makes it easier to run asynchronous tests to completion without worrying about the number of timers they use, or the delays in those timers. */ - runAll(): void; - runToLast(): void; + runAll(): number; + runToLast(): number; reset(): void; runMicrotasks(): void; - runToFrame(): void; + runToFrame(): number; Date(): Date; Date(year: number): Date; @@ -851,6 +863,8 @@ declare namespace Sinon { * @param now The new 'now' as a JavaScript Date */ setSystemTime(date: Date): void; + + countTimers(): number; } interface SinonFakeTimersConfig { diff --git a/types/sinon/ts3.1/sinon-tests.ts b/types/sinon/ts3.1/sinon-tests.ts index 8a12a01aef..fc538ecb08 100644 --- a/types/sinon/ts3.1/sinon-tests.ts +++ b/types/sinon/ts3.1/sinon-tests.ts @@ -134,19 +134,21 @@ function testClock() { let clock = sinon.clock.create(1000); clock = sinon.clock.create(new Date()); - let now = 0; + let now: sinon.SinonTimerId = 0; now = clock.now; const fn = () => { }; + const fnWithArgs = (a: number, b: string) => {}; clock.setTimeout(fn, 0); - clock.setTimeout(fn, 0, 'a', 'b'); clock.setInterval(fn, 0); - clock.setInterval(fn, 0, 'a', 'b'); clock.setImmediate(fn); - clock.setImmediate(fn, 'a', 'b'); clock.requestAnimationFrame(fn); + now = clock.setTimeout(fnWithArgs, 0, 1234, 'abc'); + now = clock.setInterval(fnWithArgs, 0, 1234, 'abc'); + now = clock.setImmediate(fnWithArgs, 1234, 'abc'); + let timer = clock.setTimeout(fn, 0); clock.clearTimeout(timer); timer = clock.setInterval(fn, 0);