Skip to content

Commit 357a524

Browse files
authored
🤖 Merge PR #61334 [sinon] support missing fake timer options by @alecgibson
At the moment, it's not possible to use some of the fake timer options, such as [`shouldClearNativeTimers`][1], because the `sinon` types uses its own hand-rolled [options object][2] which is missing the property. `@types/sinon` already has a [dependency][3] on the `fake-timers` typings, which defines its own [config object][4] with the missing properties, so this change just uses that interface directly. [1]: https://github.com/sinonjs/fake-timers/blob/3a77a0978eaccd73ccc87dd42204b54e2bac0f6f/src/fake-timers-src.js#L99 [2]: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/658b4ded756f0c98e1a22e9592014c3c6bc4323a/types/sinon/index.d.ts#L789-L793 [3]: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/658b4ded756f0c98e1a22e9592014c3c6bc4323a/types/sinon/index.d.ts#L13 [4]: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/658b4ded756f0c98e1a22e9592014c3c6bc4323a/types/sinonjs__fake-timers/index.d.ts#L335-L369
1 parent 93ea81e commit 357a524

2 files changed

Lines changed: 3 additions & 8 deletions

File tree

‎types/sinon/index.d.ts‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -786,12 +786,6 @@ declare namespace Sinon {
786786
restore(): void;
787787
};
788788

789-
interface SinonFakeTimersConfig {
790-
now: number | Date;
791-
toFake: string[];
792-
shouldAdvanceTime: boolean;
793-
}
794-
795789
interface SinonFakeUploadProgress {
796790
eventListeners: {
797791
progress: any[];
@@ -1450,7 +1444,7 @@ declare namespace Sinon {
14501444
* If set to true, the sandbox will have a clock property.
14511445
* You can optionally pass in a configuration object that follows the specification for fake timers, such as { toFake: ["setTimeout", "setInterval"] }.
14521446
*/
1453-
useFakeTimers: boolean | Partial<SinonFakeTimersConfig>;
1447+
useFakeTimers: boolean | Partial<FakeTimers.FakeTimerInstallOpts>;
14541448
/**
14551449
* If true, server and requests properties are added to the sandbox. Can also be an object to use for fake server.
14561450
* The default one is sinon.fakeServer, but if you’re using jQuery 1.3.x or some other library that does not set the XHR’s onreadystatechange handler,
@@ -1572,7 +1566,7 @@ declare namespace Sinon {
15721566
* You would have to call either clock.next(), clock.tick(), clock.runAll() or clock.runToLast() (see example below). Please refer to the lolex documentation for more information.
15731567
* @param config
15741568
*/
1575-
useFakeTimers(config?: number | Date | Partial<SinonFakeTimersConfig>): SinonFakeTimers;
1569+
useFakeTimers(config?: number | Date | Partial<FakeTimers.FakeTimerInstallOpts>): SinonFakeTimers;
15761570
/**
15771571
* Causes Sinon to replace the native XMLHttpRequest object in browsers that support it with a custom implementation which does not send actual requests.
15781572
* In browsers that support ActiveXObject, this constructor is replaced, and fake objects are returned for XMLHTTP progIds.

‎types/sinon/sinon-tests.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function testSandbox() {
3838
sb.useFakeTimers(new Date());
3939
sb.useFakeTimers({
4040
now: 1000,
41+
shouldClearNativeTimers: true,
4142
});
4243

4344
const xhr = sb.useFakeXMLHttpRequest();

0 commit comments

Comments
 (0)