Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add default for fakeTimers.toFake #5197

Merged
merged 5 commits into from Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api/vi.md
Expand Up @@ -738,7 +738,7 @@ vi.useRealTimers()

- **Type:** `() => Vitest`

To enable mocking timers, you need to call this method. It will wrap all further calls to timers (such as `setTimeout`, `setInterval`, `clearTimeout`, `clearInterval`, `nextTick`, `setImmediate`, `clearImmediate`, and `Date`), until [`vi.useRealTimers()`](#vi-userealtimers) is called.
To enable mocking timers, you need to call this method. It will wrap all further calls to timers (such as `setTimeout`, `setInterval`, `clearTimeout`, `clearInterval`, `setImmediate`, `clearImmediate`, and `Date`), until [`vi.useRealTimers()`](#vi-userealtimers) is called.
hi-ogawa marked this conversation as resolved.
Show resolved Hide resolved

Mocking `nextTick` is not supported when running Vitest inside `node:child_process` by using `--pool=forks`. NodeJS uses `process.nextTick` internally in `node:child_process` and hangs when it is mocked. Mocking `nextTick` is supported when running Vitest with `--pool=threads`.

Expand Down
5 changes: 3 additions & 2 deletions docs/config/index.md
Expand Up @@ -2035,9 +2035,10 @@ Installs fake timers with the specified Unix epoch.

#### fakeTimers.toFake

- **Type:** `FakeMethod[]`
- **Type:** `('setTimeout' | 'clearTimeout' | 'setImmediate' | 'clearImmediate' | 'setInterval' | 'clearInterval' | 'Date' | 'nextTick' | 'hrtime' | 'requestAnimationFrame' | 'cancelAnimationFrame' | 'requestIdleCallback' | 'cancelIdleCallback' | 'performance' | 'queueMicrotask')[]`
- **Default:** `['setTimeout', 'clearTimeout', 'setImmediate', 'clearImmediate', 'setInterval', 'clearInterval', 'Date']`

An array with names of global methods and APIs to fake. By default, Vitest does not replace `nextTick()` and `queueMicrotask()`.
An array with names of global methods and APIs to fake.

To only mock `setTimeout()` and `nextTick()`, specify this property as `['setTimeout', 'nextTick']`.

Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -81,7 +81,8 @@
"patchedDependencies": {
"@types/chai@4.3.6": "patches/@types__chai@4.3.6.patch",
"@sinonjs/fake-timers@11.1.0": "patches/@sinonjs__fake-timers@11.1.0.patch",
"cac@6.7.14": "patches/cac@6.7.14.patch"
"cac@6.7.14": "patches/cac@6.7.14.patch",
"@types/sinonjs__fake-timers@8.1.5": "patches/@types__sinonjs__fake-timers@8.1.5.patch"
}
},
"simple-git-hooks": {
Expand Down
34 changes: 34 additions & 0 deletions patches/@types__sinonjs__fake-timers@8.1.5.patch
@@ -0,0 +1,34 @@
diff --git a/index.d.ts b/index.d.ts
index 5aa018cde4336aca4dadefb8338549c378792e14..2e0c38efc15e793dc37e401e2513016247058f37 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -329,13 +329,15 @@ export interface FakeTimerInstallOpts {
now?: number | Date | undefined;

/**
- * An array with names of global methods and APIs to fake. By default, `@sinonjs/fake-timers` does not replace `nextTick()` and `queueMicrotask()`.
- * For instance, `FakeTimers.install({ toFake: ['setTimeout', 'nextTick'] })` will fake only `setTimeout()` and `nextTick()`
+ * An array with names of global methods and APIs to fake.
+ * For instance, `vi.useFakeTimer({ toFake: ['setTimeout', 'performance'] })` will fake only `setTimeout()` and `performance.now()`
+ * @default ['setTimeout', 'clearTimeout', 'setImmediate', 'clearImmediate', 'setInterval', 'clearInterval', 'Date']
*/
toFake?: FakeMethod[] | undefined;

/**
- * The maximum number of timers that will be run when calling runAll() (default: 1000)
+ * The maximum number of timers that will be run when calling runAll()
+ * @default 10000
*/
loopLimit?: number | undefined;

@@ -352,8 +354,8 @@ export interface FakeTimerInstallOpts {
advanceTimeDelta?: number | undefined;

/**
- * Tells FakeTimers to clear 'native' (i.e. not fake) timers by delegating to their respective handlers. These are not cleared by
- * default, leading to potentially unexpected behavior if timers existed prior to installing FakeTimers. (default: false)
+ * Tells FakeTimers to clear 'native' (i.e. not fake) timers by delegating to their respective handlers.
+ * @default true
*/
shouldClearNativeTimers?: boolean | undefined;
}
8 changes: 6 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.