Skip to content

Commit 11107dc

Browse files
committed
Merge branch 'main' into fix/project-filter-coverage
2 parents aad1474 + 6d64a3f commit 11107dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1624
-1804
lines changed

docs/.vitepress/config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export default ({ mode }: { mode: string }) => {
7070
customIcon: {
7171
'CLI': 'vscode-icons:file-type-shell',
7272
'vitest.shims': 'vscode-icons:file-type-vitest',
73-
'vitest.workspace': 'vscode-icons:file-type-vitest',
7473
'vitest.config': 'vscode-icons:file-type-vitest',
7574
'.spec.ts': 'vscode-icons:file-type-testts',
7675
'.test.ts': 'vscode-icons:file-type-testts',
@@ -546,8 +545,8 @@ function guide(): DefaultTheme.SidebarItem[] {
546545
collapsed: false,
547546
items: [
548547
{
549-
text: 'Migrating to Vitest 3.0',
550-
link: '/guide/migration#vitest-3',
548+
text: 'Migrating to Vitest 4.0',
549+
link: '/guide/migration#vitest-4',
551550
},
552551
{
553552
text: 'Migrating from Jest',

docs/.vitepress/sponsors.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ const vitestSponsors = {
4040
url: 'https://vital.io/',
4141
img: '/vital.svg',
4242
},
43+
{
44+
name: 'OOMOL',
45+
url: 'https://oomol.com/',
46+
img: '/oomol.svg',
47+
},
4348
],
4449
} satisfies Record<string, Sponsor[]>
4550

docs/api/vi.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,33 @@ expect(spy).toHaveBeenCalled()
459459
expect(spy).toHaveReturnedWith(1)
460460
```
461461

462+
If the spying method is a class definition, the mock implementations have to use the `function` or the `class` keyword:
463+
464+
```ts {12-14,16-20}
465+
const cart = {
466+
Apples: class Apples {
467+
getApples() {
468+
return 42
469+
}
470+
}
471+
}
472+
473+
const spy = vi.spyOn(cart, 'Apples')
474+
.mockImplementation(() => ({ getApples: () => 0 })) // [!code --]
475+
// with a function keyword
476+
.mockImplementation(function () {
477+
this.getApples = () => 0
478+
})
479+
// with a custom class
480+
.mockImplementation(class MockApples {
481+
getApples() {
482+
return 0
483+
}
484+
})
485+
```
486+
487+
If you provide an arrow function, you will get [`<anonymous> is not a constructor` error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Not_a_constructor) when the mock is called.
488+
462489
::: tip
463490
In environments that support [Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management), you can use `using` instead of `const` to automatically call `mockRestore` on any mocked function when the containing block is exited. This is especially useful for spied methods:
464491

docs/config/index.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,30 @@ export default defineConfig({
21912191
})
21922192
```
21932193

2194+
### onUnhandledError<NonProjectOption /> {#onunhandlederror}
2195+
2196+
- **Type:** `(error: (TestError | Error) & { type: string }) => boolean | void`
2197+
2198+
A custom handler to filter out unhandled errors that should not be reported. If an error is filtered out, it will no longer affect the test results.
2199+
2200+
If you want unhandled errors to be reported without impacting the test outcome, consider using the [`dangerouslyIgnoreUnhandledErrors`](#dangerouslyIgnoreUnhandledErrors) option
2201+
2202+
```ts
2203+
import type { ParsedStack } from 'vitest'
2204+
import { defineConfig } from 'vitest/config'
2205+
2206+
export default defineConfig({
2207+
test: {
2208+
onUnhandledError(error): boolean | void {
2209+
// Ignore all errors with the name "MySpecialError".
2210+
if (error.name === 'MySpecialError') {
2211+
return false
2212+
}
2213+
},
2214+
},
2215+
})
2216+
```
2217+
21942218
### diff
21952219

21962220
- **Type:** `string`
@@ -2338,20 +2362,6 @@ Relevant only when using with `shouldAdvanceTime: true`. increment mocked time b
23382362

23392363
Tells fake timers to clear "native" (i.e. not fake) timers by delegating to their respective handlers. When disabled, it can lead to potentially unexpected behavior if timers existed prior to starting fake timers session.
23402364

2341-
### workspace<NonProjectOption /> {#workspace}
2342-
2343-
::: danger DEPRECATED
2344-
This options is deprecated and will be removed in the next major. Please, use [`projects`](#projects) instead.
2345-
:::
2346-
2347-
- **Type:** `string | TestProjectConfiguration[]`
2348-
- **CLI:** `--workspace=./file.js`
2349-
- **Default:** `vitest.{workspace,projects}.{js,ts,json}` close to the config file or root
2350-
2351-
Path to a [workspace](/guide/projects) config file relative to [root](#root).
2352-
2353-
Since Vitest 3, you can also define the workspace array in the root config. If the `workspace` is defined in the config manually, Vitest will ignore the `vitest.workspace` file in the root.
2354-
23552365
### projects<NonProjectOption /> {#projects}
23562366

23572367
- **Type:** `TestProjectConfiguration[]`

docs/guide/cli-generated.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,6 @@ High and low watermarks for functions in the format of `<high>,<low>`
272272

273273
Override Vite mode (default: `test` or `benchmark`)
274274

275-
### workspace
276-
277-
- **CLI:** `--workspace <path>`
278-
- **Config:** [workspace](/config/#workspace)
279-
280-
[deprecated] Path to a workspace configuration file
281-
282275
### isolate
283276

284277
- **CLI:** `--isolate`

0 commit comments

Comments
 (0)