Skip to content

Commit adc52e5

Browse files
committed
typo
1 parent d578f19 commit adc52e5

5 files changed

Lines changed: 1774 additions & 776 deletions

File tree

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createSimplePlugin } from 'eslint-factory'
33

44
export default antfu(
55
{
6+
formatters: { markdown: 'prettier' },
67
stylistic: true,
78
typescript: true,
89
vue: true,

guide/snapshot.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ export default {
191191
return `Pretty foo: ${printer(val.foo, config, indentation, depth, refs)}`
192192
},
193193
test(val) {
194-
return val && Object.hasOwn(val, 'foo')
194+
return val && Object.prototype.hasOwnProperty.call(val, 'foo')
195195
},
196-
} satisfies SnapshotSerializer
196+
} satisfies SnapshotSerializ:er
197197
```
198198

199199
```ts [vitest.config.ts]
@@ -235,7 +235,7 @@ Pretty foo: Object {
235235
可通过 `vitest` 提供的 `Snapshots` 组合式函数构建自定义快照匹配器。这些函数允许你在生成快照前对值进行转换,同时完整保留快照生命周期支持(创建、更新、内联重写)。
236236

237237
```ts
238-
import { expect, Snapshots, test } from 'vitest'
238+
import { expect, test, Snapshots } from 'vitest'
239239

240240
const { toMatchFileSnapshot, toMatchInlineSnapshot, toMatchSnapshot } = Snapshots
241241

@@ -519,7 +519,7 @@ test('user data inline', () => {
519519

520520
Vitest 提供了与 [Jest](https://jestjs.io/docs/snapshot-testing) 几乎兼容的快照功能,除少数例外:
521521

522-
### 1. 快照文件中的注释标头不同 {#\_1-comment-header-in-the-snapshot-file-is-different}
522+
### 1. 快照文件中的注释标头不同 {#_1-comment-header-in-the-snapshot-file-is-different}
523523

524524
```diff
525525
- // Jest Snapshot v1, https://goo.gl/fbAQLP
@@ -528,7 +528,7 @@ Vitest 提供了与 [Jest](https://jestjs.io/docs/snapshot-testing) 几乎兼容
528528

529529
这实际上不会影响功能,但在从 Jest 迁移时可能会影响提交差异。
530530

531-
### 2. `printBasicPrototype` 默认为 `false` {#\_2-printbasicprototype-is-default-to-false}
531+
### 2. `printBasicPrototype` 默认为 `false` {#_2-printbasicprototype-is-default-to-false}
532532

533533
Jest 和 Vitest的快照功能均基于 `pretty-format` 实现,但 Vitest 在 [`@vitest/pretty-format`](https://npmx.dev/package/@vitest/pretty-format) 基础上应用了自定义的快照默认配置。具体而言,Vitest将 `printBasicPrototype` 设为 `false` 以生成更简洁的快照输出,而 Jest 29.0.0 以下版本默认将该值设为 `true`
534534

@@ -576,7 +576,7 @@ export default defineConfig({
576576
})
577577
```
578578

579-
### 3. 使用 V 形 `>` 而非冒号 `:` 作为自定义消息的分隔符 {#\_3-chevron-is-used-as-a-separator-instead-of-colon-for-custom-messages}
579+
### 3. 使用 V 形 `>` 而非冒号 `:` 作为自定义消息的分隔符 {#_3-chevron-is-used-as-a-separator-instead-of-colon-for-custom-messages}
580580

581581
当创建快照文件期间传递自定义消息时,Vitest 使用 V 形 `>` 作为分隔符而不是冒号 `:` 以提高自定义消息可读性。
582582

@@ -602,7 +602,7 @@ exports[`toThrowErrorMatchingSnapshot: hint 1`] = `"error"`;
602602
exports[`toThrowErrorMatchingSnapshot > hint 1`] = `[Error: error]`;
603603
```
604604

605-
### 4. `toThrowErrorMatchingSnapshot``toThrowErrorMatchingInlineSnapshot` 的默认 `Error` 快照不同 {#\_4-default-error-snapshot-is-different-for-tothrowerrormatchingsnapshot-and-tothrowerrormatchinginlinesnapshot}
605+
### 4. `toThrowErrorMatchingSnapshot``toThrowErrorMatchingInlineSnapshot` 的默认 `Error` 快照不同 {#_4-default-error-snapshot-is-different-for-tothrowerrormatchingsnapshot-and-tothrowerrormatchinginlinesnapshot}
606606

607607
```js
608608
import { expect, test } from 'vitest'

guide/test-tags.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ outline: deep
99

1010
## 定义标签 {#defining-tags}
1111

12-
Vitest 并未提供任何的内置标签,标签必须在配置文件中提前进行定义。如果在测试中使用了未在配置文件中定义的标签,测试运行器将会抛出错误。这一行为可以防止因标签名称拼写错误而导致的意外行为。当然你可以修改 [`strictTags`](/config/stricttags) 选项进行禁用。
12+
Vitest 并未提供任何的内置标签,标签必须在配置文件中提前进行定义。如果在测试中使用了未在配置文件中定义的标签,测试运行器将会抛出错误。这一行为可以防止因标签名称拼写错误而导致的意外行为。当然你可以修改 [`strictTags`](/config/stricttags) 选项进行禁用。
1313

1414
在标签定义时至少必须包含 `name` 参数,与此同时你还可以定义其他配置参数如 `timeout``retry`,这些配置参数将应用于使用该标签的所有测试。完整的可用配置参数,参见 [`tags`](/config/tags)
1515

@@ -60,6 +60,7 @@ test('flaky database test', { tags: ['flaky', 'db'] })
6060
test('flaky database test', { tags: ['flaky', 'db'], timeout: 120_000 })
6161
// { timeout: 120_000, retry: 3 }
6262
```
63+
6364
:::
6465

6566
如果你正在使用 TypeScript,可以扩展 `TestTags` 类型添加一个包含字符串的联合类型来限定的标签可用范围,请确保该文件被包含在 `tsconfig` 中:
@@ -193,6 +194,7 @@ describe('forms', () => {
193194
})
194195
})
195196
```
197+
196198
:::
197199

198200
## 按标签筛选用例 {#filtering-tests-by-tag}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"vue": "^3.5.29"
2323
},
2424
"devDependencies": {
25-
"@antfu/eslint-config": "^7.6.1",
25+
"@antfu/eslint-config": "^9.0.0",
2626
"@antfu/ni": "^28.3.0",
2727
"@iconify-json/carbon": "^1.2.19",
2828
"@iconify-json/logos": "^1.2.10",
@@ -37,6 +37,7 @@
3737
"@voidzero-dev/vitepress-theme": "^4.8.3",
3838
"eslint": "^10.0.3",
3939
"eslint-factory": "^0.1.2",
40+
"eslint-plugin-format": "^2.0.1",
4041
"https-localhost": "^4.7.1",
4142
"lint-staged": "^16.2.7",
4243
"pathe": "^2.0.3",

0 commit comments

Comments
 (0)