Skip to content

Commit ba2b17a

Browse files
authored
docs(cn): update /guide/migration (#940)
1 parent 687f5c8 commit ba2b17a

3 files changed

Lines changed: 58 additions & 58 deletions

File tree

api/expect.md

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ test('we don\'t have apples', () => {
334334

335335
- **类型:** `() => Awaitable<void>`
336336

337-
`toBeNullable` simply asserts if something is nullable (`null` or `undefined`).
337+
`toBeNullable` 简单地断言某些内容是否为 null(`null` `undefined`)。
338338

339339
```ts
340340
import { expect, test } from 'vitest'
@@ -435,7 +435,7 @@ test('stock is type of string', () => {
435435
```
436436

437437
:::warning
438-
`toBeTypeOf` uses the native `typeof` operator under the hood with all its quirks, most notably that the value `null` has type `object`.
438+
`toBeTypeOf` 底层使用原生 `typeof` 运算符(包含其固有特性),最显著的表现是 `null` 值会被判定为 `object` 类型。
439439

440440
```ts
441441
test('toBeTypeOf cannot check for null or array', () => {
@@ -883,7 +883,7 @@ test('matches snapshot', () => {
883883
})
884884
```
885885

886-
我们还可以提供一个对象的形状,如果我们只是测试对象的形状,而不需要它完全兼容
886+
当我们不需要完全兼容时,可以仅对对象的接口规范进行测试
887887

888888
```ts
889889
import { expect, test } from 'vitest'
@@ -919,7 +919,7 @@ test('matches inline snapshot', () => {
919919
})
920920
```
921921

922-
如果我么只是在测试对象的形状,而不需要它 100% 兼容,我们也可以提供一个对象的形状。
922+
当我们不需要完全兼容时,可以仅对对象的接口规范进行测试:
923923

924924
```ts
925925
import { expect, test } from 'vitest'
@@ -1081,7 +1081,7 @@ test('calls mock1 after mock2', () => {
10811081
})
10821082
```
10831083

1084-
## toHaveBeenCalledExactlyOnceWit
1084+
## toHaveBeenCalledExactlyOnceWith
10851085

10861086
- **类型**: `(...args: any[]) => Awaitable<void>`
10871087

@@ -1308,7 +1308,7 @@ test('spy function resolved a value two times', async () => {
13081308

13091309
## toHaveResolvedWith
13101310

1311-
- **类型**: `(returnValue: any) => Awaitable<void>`
1311+
- **类型:** `(returnValue: any) => Awaitable<void>`
13121312

13131313
您可以调用此断言来检查函数是否至少成功解析过一次某个值。需要将 spy 函数传递给`expect`
13141314

@@ -1328,7 +1328,7 @@ test('spy function resolved a product', async () => {
13281328

13291329
## toHaveLastResolvedWith
13301330

1331-
- **Type**: `(returnValue: any) => Awaitable<void>`
1331+
- **类型:** `(returnValue: any) => Awaitable<void>`
13321332

13331333
您可以调用此断言来检查函数在上次调用时是否已成功解析某个值。需要将 spy 函数传递给`expect`
13341334

@@ -1349,13 +1349,13 @@ test('spy function resolves bananas on a last call', async () => {
13491349

13501350
## toHaveNthResolvedWith
13511351

1352-
- **Type**: `(time: number, returnValue: any) => Awaitable<void>`
1352+
- **类型:** `(time: number, returnValue: any) => Awaitable<void>`
13531353

1354-
您可以调用此断言来检查函数在特定调用中是否成功解析了某个值。需要将一个间谍函数(spy function)传递给 `expect`
1354+
你可以调用此断言来检查函数在特定调用中是否成功解析了某个值。需要将一个 spy 函数传递给 `expect`
13551355

13561356
如果函数返回了一个 promise,但尚未 resolved,则将会失败。
13571357

1358-
The count starts at 1. So, to check the second entry, you would write `.toHaveNthResolvedWith(2, ...)`.
1358+
从 1 开始计数。因此,要检查第二个参数,你需要编写 `.toHaveNthResolvedWith(2, ...)`
13591359

13601360
```ts
13611361
import { expect, test, vi } from 'vitest'
@@ -1372,12 +1372,12 @@ test('spy function returns bananas on second call', async () => {
13721372

13731373
## called <Version>4.1.0</Version> {#called}
13741374

1375-
- **Type:** `Assertion` (property, not a method)
1375+
- **类型:** `Assertion` (property, not a method)
13761376

1377-
Chai-style assertion that checks if a spy was called at least once. This is equivalent to `toHaveBeenCalled()`.
1377+
这是一个检查 spy 函数是否至少被调用一次的 Chai 风格断言,等价于 `toHaveBeenCalled()`
13781378

13791379
::: tip
1380-
This is a property assertion following sinon-chai conventions. Access it without parentheses: `expect(spy).to.have.been.called`
1380+
这是一个遵循 sinon-chai 约定的属性断言。使用时无需括号:`expect(spy).to.have.been.called`
13811381
:::
13821382

13831383
```ts
@@ -1389,15 +1389,15 @@ test('spy was called', () => {
13891389
spy()
13901390

13911391
expect(spy).to.have.been.called
1392-
expect(spy).to.not.have.been.called // negation
1392+
expect(spy).to.not.have.been.called // 否定断言
13931393
})
13941394
```
13951395

13961396
## callCount <Version>4.1.0</Version> {#callcount}
13971397

1398-
- **Type:** `(count: number) => void`
1398+
- **类型:** `(count: number) => void`
13991399

1400-
Chai-style assertion that checks if a spy was called a specific number of times. This is equivalent to `toHaveBeenCalledTimes(count)`.
1400+
Chai 风格断言,用于检查 spy 函数被调用的次数是否符合预期。等价于 `toHaveBeenCalledTimes(count)`
14011401

14021402
```ts
14031403
import { expect, test, vi } from 'vitest'
@@ -1415,9 +1415,9 @@ test('spy call count', () => {
14151415

14161416
## calledWith <Version>4.1.0</Version> {#calledwith}
14171417

1418-
- **Type:** `(...args: any[]) => void`
1418+
- **类型:** `(...args: any[]) => void`
14191419

1420-
Chai-style assertion that checks if a spy was called with specific arguments at least once. This is equivalent to `toHaveBeenCalledWith(...args)`.
1420+
Chai 风格断言,用于检查 spy 函数是否至少以指定参数被调用过一次。等价于 `toHaveBeenCalledWith(...args)`
14211421

14221422
```ts
14231423
import { expect, test, vi } from 'vitest'
@@ -1435,12 +1435,12 @@ test('spy called with arguments', () => {
14351435

14361436
## calledOnce <Version>4.1.0</Version> {#calledonce}
14371437

1438-
- **Type:** `Assertion` (property, not a method)
1438+
- **类型:** `Assertion` (property, not a method)
14391439

1440-
Chai-style assertion that checks if a spy was called exactly once. This is equivalent to `toHaveBeenCalledOnce()`.
1440+
Chai 风格断言,用于检查 spy 函数是否恰好被调用了一次。等价于 `toHaveBeenCalledOnce()`
14411441

14421442
::: tip
1443-
This is a property assertion following sinon-chai conventions. Access it without parentheses: `expect(spy).to.have.been.calledOnce`
1443+
这是遵循 sinon-chai 约定的属性断言,使用时无需括号:`expect(spy).to.have.been.calledOnce`
14441444
:::
14451445

14461446
```ts
@@ -1457,9 +1457,9 @@ test('spy called once', () => {
14571457

14581458
## calledOnceWith <Version>4.1.0</Version> {#calledoncewith}
14591459

1460-
- **Type:** `(...args: any[]) => void`
1460+
- **类型:** `(...args: any[]) => void`
14611461

1462-
Chai-style assertion that checks if a spy was called exactly once with specific arguments. This is equivalent to `toHaveBeenCalledExactlyOnceWith(...args)`.
1462+
Chai 风格断言,用于检查 spy 函数是否恰好以指定参数被调用了一次。等价于 `toHaveBeenCalledExactlyOnceWith(...args)`
14631463

14641464
```ts
14651465
import { expect, test, vi } from 'vitest'
@@ -1475,12 +1475,12 @@ test('spy called once with arguments', () => {
14751475

14761476
## calledTwice <Version>4.1.0</Version> {#calledtwice}
14771477

1478-
- **Type:** `Assertion` (property, not a method)
1478+
- **类型:** `Assertion` (property, not a method)
14791479

1480-
Chai-style assertion that checks if a spy was called exactly twice. This is equivalent to `toHaveBeenCalledTimes(2)`.
1480+
Chai 风格断言,用于检查 spy 函数是否恰好被调用了两次。等价于 `toHaveBeenCalledTimes(2)`
14811481

14821482
::: tip
1483-
This is a property assertion following sinon-chai conventions. Access it without parentheses: `expect(spy).to.have.been.calledTwice`
1483+
这是遵循 sinon-chai 约定的属性断言,使用时无需括号:`expect(spy).to.have.been.calledTwice`
14841484
:::
14851485

14861486
```ts
@@ -1498,12 +1498,12 @@ test('spy called twice', () => {
14981498

14991499
## calledThrice <Version>4.1.0</Version> {#calledthrice}
15001500

1501-
- **Type:** `Assertion` (property, not a method)
1501+
- **类型:** `Assertion` (property, not a method)
15021502

1503-
Chai-style assertion that checks if a spy was called exactly three times. This is equivalent to `toHaveBeenCalledTimes(3)`.
1503+
Chai 风格断言,用于检查 spy 函数是否恰好被调用了三次。等价于 `toHaveBeenCalledTimes(3)`
15041504

15051505
::: tip
1506-
This is a property assertion following sinon-chai conventions. Access it without parentheses: `expect(spy).to.have.been.calledThrice`
1506+
这是遵循 sinon-chai 约定的属性断言,使用时无需括号:`expect(spy).to.have.been.calledThrice`
15071507
:::
15081508

15091509
```ts
@@ -1522,9 +1522,9 @@ test('spy called thrice', () => {
15221522

15231523
## lastCalledWith
15241524

1525-
- **Type:** `(...args: any[]) => void`
1525+
- **类型:** `(...args: any[]) => void`
15261526

1527-
Chai-style assertion that checks if the last call to a spy was made with specific arguments. This is equivalent to `toHaveBeenLastCalledWith(...args)`.
1527+
Chai 风格断言,用于检查 spy 函数最后一次调用是否使用了指定参数。等价于 `toHaveBeenLastCalledWith(...args)`
15281528

15291529
```ts
15301530
import { expect, test, vi } from 'vitest'
@@ -1541,9 +1541,9 @@ test('spy last called with', () => {
15411541

15421542
## nthCalledWith
15431543

1544-
- **Type:** `(n: number, ...args: any[]) => void`
1544+
- **类型:** `(n: number, ...args: any[]) => void`
15451545

1546-
Chai-style assertion that checks if the nth call to a spy was made with specific arguments. This is equivalent to `toHaveBeenNthCalledWith(n, ...args)`.
1546+
Chai 风格断言,用于检查 spy 函数第 n 次调用是否使用了指定参数。等价于 `toHaveBeenNthCalledWith(n, ...args)`
15471547

15481548
```ts
15491549
import { expect, test, vi } from 'vitest'
@@ -1561,12 +1561,12 @@ test('spy nth called with', () => {
15611561

15621562
## returned <Version>4.1.0</Version> {#returned}
15631563

1564-
- **Type:** `Assertion` (property, not a method)
1564+
- **类型:** `Assertion` (property, not a method)
15651565

1566-
Chai-style assertion that checks if a spy returned successfully at least once. This is equivalent to `toHaveReturned()`.
1566+
Chai 风格断言,用于检查 spy 函数是否至少成功返回过一次。等价于 `toHaveReturned()`
15671567

15681568
::: tip
1569-
This is a property assertion following sinon-chai conventions. Access it without parentheses: `expect(spy).to.have.returned`
1569+
这是遵循 sinon-chai 约定的属性断言,使用时无需括号:`expect(spy).to.have.returned`
15701570
:::
15711571

15721572
```ts
@@ -1583,9 +1583,9 @@ test('spy returned', () => {
15831583

15841584
## returnedWith <Version>4.1.0</Version> {#returnedwith}
15851585

1586-
- **Type:** `(value: any) => void`
1586+
- **类型:** `(value: any) => void`
15871587

1588-
Chai-style assertion that checks if a spy returned a specific value at least once. This is equivalent to `toHaveReturnedWith(value)`.
1588+
Chai 风格断言,用于检查 spy 函数是否至少返回过一次指定的值。等价于 `toHaveReturnedWith(value)`
15891589

15901590
```ts
15911591
import { expect, test, vi } from 'vitest'
@@ -1605,9 +1605,9 @@ test('spy returned with value', () => {
16051605

16061606
## returnedTimes <Version>4.1.0</Version> {#returnedtimes}
16071607

1608-
- **Type:** `(count: number) => void`
1608+
- **类型:** `(count: number) => void`
16091609

1610-
Chai-style assertion that checks if a spy returned successfully a specific number of times. This is equivalent to `toHaveReturnedTimes(count)`.
1610+
Chai 风格断言,用于检查 spy 函数成功返回的次数是否符合预期。等价于 `toHaveReturnedTimes(count)`
16111611

16121612
```ts
16131613
import { expect, test, vi } from 'vitest'
@@ -1625,9 +1625,9 @@ test('spy returned times', () => {
16251625

16261626
## lastReturnedWith
16271627

1628-
- **Type:** `(value: any) => void`
1628+
- **类型:** `(value: any) => void`
16291629

1630-
Chai-style assertion that checks if the last return value of a spy matches the expected value. This is equivalent to `toHaveLastReturnedWith(value)`.
1630+
Chai 风格断言,用于检查 spy 函数最后一次返回值是否与预期值匹配。等价于 `toHaveLastReturnedWith(value)`
16311631

16321632
```ts
16331633
import { expect, test, vi } from 'vitest'
@@ -1646,9 +1646,9 @@ test('spy last returned with', () => {
16461646

16471647
## nthReturnedWith
16481648

1649-
- **Type:** `(n: number, value: any) => void`
1649+
- **类型:** `(n: number, value: any) => void`
16501650

1651-
Chai-style assertion that checks if the nth return value of a spy matches the expected value. This is equivalent to `toHaveNthReturnedWith(n, value)`.
1651+
Chai 风格断言,用于检查 spy 函数第 n 次返回值是否与预期值匹配。等价于 `toHaveNthReturnedWith(n, value)`
16521652

16531653
```ts
16541654
import { expect, test, vi } from 'vitest'
@@ -1669,9 +1669,9 @@ test('spy nth returned with', () => {
16691669

16701670
## calledBefore <Version>4.1.0</Version> {#calledbefore}
16711671

1672-
- **Type:** `(mock: MockInstance, failIfNoFirstInvocation?: boolean) => void`
1672+
- **类型:** `(mock: MockInstance, failIfNoFirstInvocation?: boolean) => void`
16731673

1674-
Chai-style assertion that checks if a spy was called before another spy. This is equivalent to `toHaveBeenCalledBefore(mock, failIfNoFirstInvocation)`.
1674+
Chai 风格断言,用于检查一个 spy 函数是否在另一个 spy 函数之前被调用。等价于 `toHaveBeenCalledBefore(mock, failIfNoFirstInvocation)`
16751675

16761676
```ts
16771677
import { expect, test, vi } from 'vitest'
@@ -1689,9 +1689,9 @@ test('spy called before another', () => {
16891689

16901690
## calledAfter <Version>4.1.0</Version> {#calledafter}
16911691

1692-
- **Type:** `(mock: MockInstance, failIfNoFirstInvocation?: boolean) => void`
1692+
- **类型:** `(mock: MockInstance, failIfNoFirstInvocation?: boolean) => void`
16931693

1694-
Chai-style assertion that checks if a spy was called after another spy. This is equivalent to `toHaveBeenCalledAfter(mock, failIfNoFirstInvocation)`.
1694+
Chai 风格断言,用于检查一个 spy 函数是否在另一个 spy 函数之后被调用。等价于 `toHaveBeenCalledAfter(mock, failIfNoFirstInvocation)`
16951695

16961696
```ts
16971697
import { expect, test, vi } from 'vitest'
@@ -1707,8 +1707,8 @@ test('spy called after another', () => {
17071707
})
17081708
```
17091709

1710-
::: tip Migration Guide
1711-
For a complete guide on migrating from Mocha+Chai+Sinon to Vitest, see the [Migration Guide](/guide/migration#mocha-chai-sinon).
1710+
::: tip 迁移指南
1711+
完整的从 Mocha+Chai+Sinon 迁移到 Vitest 的指南,请参阅 [迁移指南](/guide/migration#mocha-chai-sinon)
17121712
:::
17131713

17141714
## toSatisfy
@@ -1988,7 +1988,7 @@ test('basket includes fuji', () => {
19881988

19891989
- **类型:** `(expected: any) => any`
19901990

1991-
当与相等检查一起使用时,如果值的形状相似,该非对称匹配器将返回 `true`
1991+
当与相等检查一起使用时,如果值的接口规范相似,该非对称匹配器将返回 `true`
19921992

19931993
```ts
19941994
import { expect, test } from 'vitest'
@@ -2077,25 +2077,25 @@ import { type } from 'arktype'
20772077
test('email validation', () => {
20782078
const user = { email: 'john@example.com' }
20792079

2080-
// using Zod
2080+
// 使用 Zod
20812081
expect(user).toEqual({
20822082
email: expect.schemaMatching(z.string().email()),
20832083
})
20842084

2085-
// using Valibot
2085+
// 使用 Valibot
20862086
expect(user).toEqual({
20872087
email: expect.schemaMatching(v.pipe(v.string(), v.email()))
20882088
})
20892089

2090-
// using ArkType
2090+
// 使用 ArkType
20912091
expect(user).toEqual({
20922092
email: expect.schemaMatching(type('string.email')),
20932093
})
20942094
})
20952095
```
20962096

20972097
:::tip
2098-
You can use `expect.not` with this matcher to negate the expected value.
2098+
可以通过 `expect.not` 结合此匹配器来对期望值进行取反断言。
20992099
:::
21002100

21012101
## expect.addSnapshotSerializer
@@ -2107,7 +2107,7 @@ You can use `expect.not` with this matcher to negate the expected value.
21072107
如果需要添加自定义序列化程序,应该在 [`setupFiles`](/config/setupfiles) 中调用此方法。这将影响每个快照。
21082108

21092109
:::tip
2110-
如果以前将 Vue CLI 与 Jest 一起使用,需要安装 [jest-serializer-vue](https://www.npmjs.com/package/jest-serializer-vue)。 否则,的快照将被包裹在一个字符串中,其中 `"` 是要转义的。
2110+
如果以前将 Vue CLI 与 Jest 一起使用,需要安装 [jest-serializer-vue](https://www.npmjs.com/package/jest-serializer-vue)。 否则,快照将被包裹在一个字符串中,其中 `"` 是要转义的。
21112111
:::
21122112

21132113
## expect.extend

guide/migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ expect(spy).to.have.been.calledOnce
711711
expect(spy).to.have.been.calledWith('arg1', 'arg2')
712712
```
713713

714-
#### 完整的 Chai 风格断言支持 {#}complete-chai-style-assertion-support}
714+
#### 完整的 Chai 风格断言支持 {#complete-chai-style-assertion-support}
715715

716716
Vitest supports all common sinon-chai assertions:
717717

guide/open-telemetry.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export default defineConfig({
141141

142142
生成追踪数据时,请像往常一样运行 Vitest,无论是 watch 模式还是运行模式均可。Vitest 会在所有操作完成后手动调用 `sdk.shutdown()` 以确保追踪数据得到正确处理。
143143

144-
你可以使用任何支持 OpenTelemetry API 的开源或商业产品来查看追踪。如果是初次接触 OpenTelemetry,我们推荐从 [Jaeger](https://www.jaegertracing.io/docs/2.11/getting-started/#all-in-one) 开始,因为它真的很容易设置。
144+
你可以使用任何支持 OpenTelemetry API 的开源或商业产品来查看追踪。如果是初次接触 OpenTelemetry,我们推荐从 [Jaeger](https://www.jaegertracing.io/docs/2.11/getting-started/#all-in-one) 开始,因为它真的很容易设置。
145145

146146
<img src="/otel-jaeger.png" />
147147

0 commit comments

Comments
 (0)