Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,10 @@ export default ({ mode }: { mode: string }) => {
text: 'retry',
link: '/config/retry',
},
{
text: 'repeats',
link: '/config/repeats',
},
{
text: 'onConsoleLog',
link: '/config/onconsolelog',
Expand Down
28 changes: 28 additions & 0 deletions api/assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@

Vitest 从 [`chai`](https://www.chaijs.com/api/assert/) 重新导出了 `assert` 方法,用于验证不变量。

::: warning In-Source Testing {#in-source-testing}
When using [assertion functions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions) such as `assert` from `import.meta.vitest` in [in-source tests](/guide/in-source), TypeScript reports error `TS2775` because they must be called via an explicitly annotated name. Annotate the variable with `Chai.Assert` or call it directly:

::: code-group
```ts [Annotated variable]
if (import.meta.vitest) {
const { test, assert } = import.meta.vitest // [!code --]
const { test } = import.meta.vitest // [!code ++]
const assert: Chai.Assert = import.meta.vitest.assert // [!code ++]

test('assert', () => {
assert('foo' !== 'bar', 'foo should not be equal to bar')
})
}
```
```ts [Direct call]
if (import.meta.vitest) {
const { test, assert } = import.meta.vitest // [!code --]
const { test } = import.meta.vitest // [!code ++]

test('assert', () => {
assert('foo' !== 'bar', 'foo should not be equal to bar') // [!code --]
import.meta.vitest!.assert('foo' !== 'bar', 'foo should not be equal to bar') // [!code ++]
})
}
```
:::

## assert

- **类型:** `(expression: any, message?: string) => asserts expression`
Expand Down
14 changes: 14 additions & 0 deletions config/repeats.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: repeats | Config
outline: deep
---

# repeats

- **Type:** `number`
- **Default:** `0`
- **CLI:** `--repeats=<number>`

Repeat every test a specific number of times regardless of the result. A test that uses the [`repeats`](/api/test#repeats) test option takes precedence over this value.

This is useful for verifying that tests are stable across multiple runs. If a test fails on any repetition, the whole test is reported as failed.
7 changes: 7 additions & 0 deletions guide/cli-generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,13 @@ UI 模式和 HTML 报告器中提供的 HTML 覆盖率输出目录。

触发重试操作的错误信息匹配正则表达式。仅当错误信息符合该模式时才会执行重试(默认值:所有错误都会触发重试)

### repeats

- **CLI:** `--repeats <number>`
- **Config:** [repeats](/config/repeats)

Repeat every test a specific number of times regardless of the result (default: `0`)

### diff.aAnnotation

- **命令行终端:** `--diff.aAnnotation <annotation>`
Expand Down
8 changes: 8 additions & 0 deletions guide/in-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,15 @@ module.exports = {

完整的示例请参考 [`examples/in-source-test`](https://github.com/vitest-dev/vitest/tree/main/examples/in-source-test)。

<<<<<<< HEAD
## 说明 {#notes}
=======
Comment on lines +158 to +160

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Resolve the leftover merge conflict markers

This leaves an unresolved merge conflict in the published guide/in-source.md page (<<<<<<< HEAD, =======, and the matching >>>>>>> at line 166). In the generated docs this section will show raw conflict text and both competing headings/content instead of the intended Chinese Notes section plus warning, so the merge needs to be resolved before shipping.

Useful? React with 👍 / 👎.

::: warning
There is a limitation when using [assertion functions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions) such as `assert` in in-source tests. See [`assert`](/api/assert#in-source-testing) for details and workarounds.
:::

## Notes
>>>>>>> 2faf0d3031b3c8fea4349f2fb70e9199a71e8a72

此功能可用于:

Expand Down
Loading