Skip to content

Commit d5ea43e

Browse files
authored
Merge pull request #775 from WuMingDao/fix-in-api-transalte
docs(api/*): check translate
2 parents 749cba2 + f47709f commit d5ea43e

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

api/assert-type.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
你可以使用此函数作为 [`expectTypeOf`](/api/expect-typeof) 的替代方法,以轻松地断言参数类型等于提供的泛型。
66

77
::: warning
8-
在运行时,此函数不执行任何操作。要 [enable typechecking](/guide/testing-types#run-typechecking),不要忘记传递 `--typecheck` 标志。
8+
在运行时,此函数不执行任何操作。要 [启用 typechecking](/guide/testing-types#run-typechecking),不要忘记传递 `--typecheck` 标志。
99
:::
1010

1111
```ts
@@ -17,6 +17,6 @@ function concat(a: string | number, b: string | number): string | number
1717

1818
assertType<string>(concat('a', 'b'))
1919
assertType<number>(concat(1, 2))
20-
// @ts-expect-error wrong types
20+
// @ts-expect-error 错误类型
2121
assertType(concat('a', 2))
2222
```

api/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,9 +974,9 @@ describe.concurrent('suite', () => {
974974

975975
```ts
976976
describe.concurrent(/* ... */)
977-
describe.skip.concurrent(/* ... */) // or describe.concurrent.skip(/* ... */)
978-
describe.only.concurrent(/* ... */) // or describe.concurrent.only(/* ... */)
979-
describe.todo.concurrent(/* ... */) // or describe.concurrent.todo(/* ... */)
977+
describe.skip.concurrent(/* ... */) // describe.concurrent.skip(/* ... */)
978+
describe.only.concurrent(/* ... */) // describe.concurrent.only(/* ... */)
979+
describe.todo.concurrent(/* ... */) // describe.concurrent.todo(/* ... */)
980980
```
981981

982982
运行并发测试时,快照和断言必须使用本地[测试上下文](/guide/test-context.md)中的 `expect` ,以确保检测到正确的测试。

api/mock.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const spy = vi.spyOn(person, 'greet').mockImplementation(() => 'mocked')
6060
expect(person.greet('Alice')).toBe('mocked')
6161
expect(spy.mock.calls).toEqual([['Alice']])
6262
63-
// clear call history but keep mock implementation
63+
// 清空历史,但是保留模拟对象的实现
6464
spy.mockClear()
6565
expect(spy.mock.calls).toEqual([])
6666
expect(person.greet('Bob')).toBe('mocked')
@@ -87,7 +87,7 @@ function mockImplementation(fn: T): Mock<T>
8787

8888
```ts
8989
const mockFn = vi.fn().mockImplementation((apples: number) => apples + 1)
90-
// or: vi.fn(apples => apples + 1);
90+
// 或:vi.fn(apples => apples + 1);
9191
9292
const NelliesBucket = mockFn(0)
9393
const BobsBucket = mockFn(1)
@@ -110,11 +110,11 @@ function mockImplementationOnce(fn: T): Mock<T>
110110
```ts
111111
const myMockFn = vi
112112
.fn()
113-
.mockImplementationOnce(() => true) // 1st call
114-
.mockImplementationOnce(() => false) // 2nd call
113+
.mockImplementationOnce(() => true) // 1st 调用
114+
.mockImplementationOnce(() => false) // 2nd 调用
115115
116-
myMockFn() // 1st call: true
117-
myMockFn() // 2nd call: false
116+
myMockFn() // 1st 调用:true
117+
myMockFn() // 2nd 调用:false
118118
```
119119

120120
mock 函数用完所有实现后,如果之前调用过 `vi.fn(() => defaultValue)``.mockImplementation(() => defaultValue)`,它将调用设置的默认实现:
@@ -163,7 +163,7 @@ myMockFn() // 'original'
163163
test('async callback', () => {
164164
const myMockFn = vi.fn(() => 'original')
165165
166-
// We await this call since the callback is async
166+
// 由于回调是异步的,我们要等待这个调用
167167
await myMockFn.withImplementation(
168168
() => 'temp',
169169
async () => {
@@ -188,7 +188,7 @@ function mockRejectedValue(value: unknown): Mock<T>
188188
```ts
189189
const asyncMock = vi.fn().mockRejectedValue(new Error('Async error'))
190190
191-
await asyncMock() // throws Error<'Async error'>
191+
await asyncMock() // 抛出 Error<'Async error'>
192192
```
193193

194194
## mockRejectedValueOnce
@@ -206,7 +206,7 @@ const asyncMock = vi
206206
.mockRejectedValueOnce(new Error('Async error'))
207207
208208
await asyncMock() // 'first call'
209-
await asyncMock() // throws Error<'Async error'>
209+
await asyncMock() // 抛出 Error<'Async error'>
210210
```
211211

212212
## mockReset
@@ -233,7 +233,7 @@ const spy = vi.spyOn(person, 'greet').mockImplementation(() => 'mocked')
233233
expect(person.greet('Alice')).toBe('mocked')
234234
expect(spy.mock.calls).toEqual([['Alice']])
235235
236-
// clear call history and reset implementation, but method is still spied
236+
// 清空历史和重置实现,但是方法依然是被监视
237237
spy.mockReset()
238238
expect(spy.mock.calls).toEqual([])
239239
expect(person.greet).toBe(spy)
@@ -261,7 +261,7 @@ const spy = vi.spyOn(person, 'greet').mockImplementation(() => 'mocked')
261261
expect(person.greet('Alice')).toBe('mocked')
262262
expect(spy.mock.calls).toEqual([['Alice']])
263263
264-
// clear call history and restore spied object method
264+
// 清空调用历史和恢复被监视对象方法
265265
spy.mockRestore()
266266
expect(spy.mock.calls).toEqual([])
267267
expect(person.greet).not.toBe(spy)
@@ -392,8 +392,8 @@ argument.value = 10
392392
393393
expect(fn).toHaveBeenCalledWith({ value: 0 }) // [!code --]
394394
395-
// The equality check is done against the original argument,
396-
// but its property was changed between the call and assertion
395+
// 相等性检查是针对原始参数进行的,
396+
// 但是,该参数的属性在调用和断言之间发生了更改。
397397
expect(fn).toHaveBeenCalledWith({ value: 10 }) // [!code ++]
398398
```
399399

@@ -423,8 +423,8 @@ const lastCall: Parameters<T> | undefined
423423
interface MockResultReturn<T> {
424424
type: 'return'
425425
/**
426-
* The value that was returned from the function.
427-
* If the function returned a Promise, then this will be a resolved value.
426+
* 函数返回的值。
427+
* 如果函数返回的是一个 Promise,那么这将是一个已解析的值。
428428
*/
429429
value: T
430430
}
@@ -437,7 +437,7 @@ interface MockResultIncomplete {
437437
interface MockResultThrow {
438438
type: 'throw'
439439
/**
440-
* An error that was thrown during function execution.
440+
* 函数执行过程中抛出的错误。
441441
*/
442442
value: any
443443
}
@@ -466,21 +466,21 @@ const fn = vi
466466
throw new Error('thrown error')
467467
})
468468
469-
const result = fn() // returned 'result'
469+
const result = fn() // 返回 'result'
470470
471471
try {
472-
fn() // threw Error
472+
fn() // 抛出错误
473473
}
474474
catch {}
475475
476476
fn.mock.results
477477
=== [
478-
// first result
478+
// 首个结果
479479
{
480480
type: 'return',
481481
value: 'result',
482482
},
483-
// last result
483+
// 最后结果
484484
{
485485
type: 'throw',
486486
value: Error,

0 commit comments

Comments
 (0)