@@ -117,7 +117,7 @@ myTest('add item', ({ todos }) => {
117
117
import { assert , test } from ' vitest'
118
118
119
119
test .skip (' skipped test' , () => {
120
- // Test skipped, no error
120
+ // 测试被跳过,没有错误。
121
121
assert .equal (Math .sqrt (4 ), 3 )
122
122
})
123
123
```
@@ -129,7 +129,7 @@ import { assert, test } from 'vitest'
129
129
130
130
test (' skipped test' , (context ) => {
131
131
context .skip ()
132
- // Test skipped, no error
132
+ // 测试被跳过,没有错误。
133
133
assert .equal (Math .sqrt (4 ), 3 )
134
134
})
135
135
```
@@ -147,7 +147,7 @@ import { assert, test } from 'vitest'
147
147
const isDev = process .env .NODE_ENV === ' development'
148
148
149
149
test .skipIf (isDev )(' prod only test' , () => {
150
- // this test only runs in production
150
+ // 此测试仅在生产环境中运行。
151
151
})
152
152
```
153
153
@@ -168,7 +168,7 @@ import { assert, test } from 'vitest'
168
168
const isDev = process .env .NODE_ENV === ' development'
169
169
170
170
test .runIf (isDev )(' dev only test' , () => {
171
- // this test only runs in development
171
+ // 此测试仅在开发环境中运行。
172
172
})
173
173
```
174
174
@@ -189,7 +189,7 @@ test.runIf(isDev)('dev only test', () => {
189
189
import { assert , test } from ' vitest'
190
190
191
191
test .only (' test' , () => {
192
- // Only this test (and others marked with only) are run
192
+ // 只有此测试(以及其他标记为 ` only` 的测试)会被运行。
193
193
assert .equal (Math .sqrt (4 ), 2 )
194
194
})
195
195
```
@@ -212,7 +212,7 @@ test.only('test', () => {
212
212
``` ts
213
213
import { describe , test } from ' vitest'
214
214
215
- // The two tests marked with concurrent will be run in parallel
215
+ // 标记为 ` concurrent` 的两个测试将并行运行。
216
216
describe (' suite' , () => {
217
217
test (' serial test' , async () => {
218
218
/* ... */
@@ -259,7 +259,7 @@ test.concurrent('test 2', async ({ expect }) => {
259
259
``` ts
260
260
import { describe , test } from ' vitest'
261
261
262
- // with config option { sequence: { concurrent: true } }
262
+ // 使用配置选项 ` { sequence: { concurrent: true } }`
263
263
test (' concurrent test 1' , async () => {
264
264
/* ... */
265
265
})
@@ -274,7 +274,7 @@ test.sequential('sequential test 2', async () => {
274
274
/* ... */
275
275
})
276
276
277
- // within concurrent suite
277
+ // 在并发套件中
278
278
describe .concurrent (' suite' , () => {
279
279
test (' concurrent test 1' , async () => {
280
280
/* ... */
@@ -300,7 +300,7 @@ describe.concurrent('suite', () => {
300
300
使用 ` test.todo ` 来存根测试,以便稍后实施。测试报告中将显示一个条目,以便知道还有多少测试需要执行。
301
301
302
302
``` ts
303
- // An entry will be shown in the report for this test
303
+ // 此测试将在报告中显示一个条目。
304
304
test .todo (' unimplemented test' )
305
305
```
306
306
@@ -358,7 +358,7 @@ test.each([
358
358
expect (a + b ).toBe (expected )
359
359
})
360
360
361
- // this will return
361
+ // 这将返回
362
362
// ✓ add(1, 1) -> 2
363
363
// ✓ add(1, 2) -> 3
364
364
// ✓ add(2, 1) -> 3
@@ -375,7 +375,7 @@ test.each([
375
375
expect (a + b ).toBe (expected )
376
376
})
377
377
378
- // this will return
378
+ // 这将返回
379
379
// ✓ add(1, 1) -> 2
380
380
// ✓ add(1, 2) -> 3
381
381
// ✓ add(2, 1) -> 3
@@ -395,7 +395,7 @@ test.each`
395
395
expect (a .val + b ).toBe (expected )
396
396
})
397
397
398
- // this will return
398
+ // 这将返回
399
399
// ✓ add(1, b) -> 1b
400
400
// ✓ add(2, b) -> 2b
401
401
// ✓ add(3, b) -> 3b
@@ -438,7 +438,7 @@ Vitest 使用 chai `format` 方法处理 `$values`。如果数值太短,可以
438
438
其他非数组情况(包括模板字符串的使用)完全相同。
439
439
440
440
``` ts
441
- // `each` spreads array case
441
+ // `each` 展开数组用例
442
442
test .each ([
443
443
[1 , 1 , 2 ],
444
444
[1 , 2 , 3 ],
@@ -447,7 +447,7 @@ test.each([
447
447
expect (a + b ).toBe (expected )
448
448
})
449
449
450
- // `for` doesn't spread array case
450
+ // `for` 不会展开数组用例
451
451
test .for ([
452
452
[1 , 1 , 2 ],
453
453
[1 , 2 , 3 ],
@@ -837,7 +837,7 @@ import { assert, describe, test } from 'vitest'
837
837
const isDev = process .env .NODE_ENV === ' development'
838
838
839
839
describe .runIf (isDev )(' dev only test suite' , () => {
840
- // this test suite only runs in development
840
+ // 此测试套件仅在开发环境中运行。
841
841
})
842
842
```
843
843
@@ -854,15 +854,15 @@ describe.runIf(isDev)('dev only test suite', () => {
854
854
``` ts
855
855
import { assert , describe , test } from ' vitest'
856
856
857
- // Only this suite (and others marked with only) are run
857
+ // 只有此测试套件(以及其他标记为 ` only` 的测试套件)会被运行。
858
858
describe .only (' suite' , () => {
859
859
test (' sqrt' , () => {
860
860
assert .equal (Math .sqrt (4 ), 3 )
861
861
})
862
862
})
863
863
864
864
describe (' other suite' , () => {
865
- // ... will be skipped
865
+ // ... 将被跳过
866
866
})
867
867
```
868
868
@@ -885,7 +885,7 @@ In order to do that run `vitest` with specific file containing the tests in ques
885
885
``` ts
886
886
import { describe , test } from ' vitest'
887
887
888
- // All suites and tests within this suite will be run in parallel
888
+ // 此测试套件中的所有测试套件和测试将并行运行。
889
889
describe .concurrent (' suite' , () => {
890
890
test (' concurrent test 1' , async () => {
891
891
/* ... */
@@ -967,25 +967,25 @@ Vitest 通过 CLI 标志 [`--sequence.shuffle`](/guide/cli) 或配置选项 [`se
967
967
``` ts
968
968
import { describe , test } from ' vitest'
969
969
970
- // or describe('suite', { shuffle: true }, ...)
970
+ // 或 ` describe('suite', { shuffle: true }, ...)`
971
971
describe .shuffle (' suite' , () => {
972
972
test (' random test 1' , async () => { /* ... */ })
973
973
test (' random test 2' , async () => { /* ... */ })
974
974
test (' random test 3' , async () => { /* ... */ })
975
975
976
- // `shuffle` is inherited
976
+ // `shuffle` 是继承的
977
977
describe (' still random' , () => {
978
978
test (' random 4.1' , async () => { /* ... */ })
979
979
test (' random 4.2' , async () => { /* ... */ })
980
980
})
981
981
982
- // disable shuffle inside
982
+ // 禁用内部的 shuffle
983
983
describe (' not random' , { shuffle: false }, () => {
984
984
test (' in order 5.1' , async () => { /* ... */ })
985
985
test (' in order 5.2' , async () => { /* ... */ })
986
986
})
987
987
})
988
- // order depends on sequence.seed option in config ( Date.now() by default)
988
+ // 顺序取决于配置中的 ` sequence.seed` 选项(默认为 ` Date.now()`)
989
989
```
990
990
991
991
` .skip ` 、` .only ` 和` .todo ` 适用于随机测试套件。
@@ -1001,7 +1001,7 @@ describe.shuffle('suite', () => {
1001
1001
使用 ` describe.todo ` 来暂存待以后实施的套件。测试报告中会显示一个条目,这样就能知道还有多少测试需要执行。
1002
1002
1003
1003
``` ts
1004
- // An entry will be shown in the report for this suite
1004
+ // 此测试套件将在报告中显示一个条目。
1005
1005
describe .todo (' unimplemented suite' )
1006
1006
```
1007
1007
@@ -1072,7 +1072,7 @@ The difference from `describe.each` is how array case is provided in the argumen
1072
1072
Other non array case (including template string usage) works exactly same.
1073
1073
1074
1074
``` ts
1075
- // `each` spreads array case
1075
+ // `each` 展开数组用例
1076
1076
describe .each ([
1077
1077
[1 , 1 , 2 ],
1078
1078
[1 , 2 , 3 ],
@@ -1083,7 +1083,7 @@ describe.each([
1083
1083
})
1084
1084
})
1085
1085
1086
- // `for` doesn't spread array case
1086
+ // `for` 不会展开数组用例
1087
1087
describe .for ([
1088
1088
[1 , 1 , 2 ],
1089
1089
[1 , 2 , 3 ],
@@ -1113,7 +1113,7 @@ describe.for([
1113
1113
import { beforeEach } from ' vitest'
1114
1114
1115
1115
beforeEach (async () => {
1116
- // Clear mocks and add some testing data after before each test run
1116
+ // 在每个测试运行之前清除模拟并添加一些测试数据。
1117
1117
await stopMocking ()
1118
1118
await addUser ({ name: ' John' })
1119
1119
})
@@ -1127,10 +1127,10 @@ beforeEach(async () => {
1127
1127
import { beforeEach } from ' vitest'
1128
1128
1129
1129
beforeEach (async () => {
1130
- // called once before each test run
1130
+ // 在每个测试运行之前调用一次。
1131
1131
await prepareSomething ()
1132
1132
1133
- // clean up function, called once after each test run
1133
+ // 清理函数,在每个测试运行之后调用一次。
1134
1134
return async () => {
1135
1135
await resetSomething ()
1136
1136
}
@@ -1150,7 +1150,7 @@ beforeEach(async () => {
1150
1150
import { afterEach } from ' vitest'
1151
1151
1152
1152
afterEach (async () => {
1153
- await clearTestingData () // clear testing data after each test run
1153
+ await clearTestingData () // 在每个测试运行之后清除测试数据。
1154
1154
})
1155
1155
```
1156
1156
@@ -1173,7 +1173,7 @@ Vitest 在 1.3.0 新增 [`onTestFinished`](#ontestfinished)。你可以在测试
1173
1173
import { beforeAll } from ' vitest'
1174
1174
1175
1175
beforeAll (async () => {
1176
- await startMocking () // called once before all tests run
1176
+ await startMocking () // 在所有测试运行之前调用一次。
1177
1177
})
1178
1178
```
1179
1179
@@ -1185,10 +1185,10 @@ beforeAll(async () => {
1185
1185
import { beforeAll } from ' vitest'
1186
1186
1187
1187
beforeAll (async () => {
1188
- // called once before all tests run
1188
+ // 在所有测试运行之前调用一次。
1189
1189
await startMocking ()
1190
1190
1191
- // clean up function, called once after all tests run
1191
+ // 清理函数,在所有测试运行之后调用一次。
1192
1192
return async () => {
1193
1193
await stopMocking ()
1194
1194
}
@@ -1208,7 +1208,7 @@ beforeAll(async () => {
1208
1208
import { afterAll } from ' vitest'
1209
1209
1210
1210
afterAll (async () => {
1211
- await stopMocking () // this method is called after all tests run
1211
+ await stopMocking () // 此方法在所有测试运行之后被调用。
1212
1212
})
1213
1213
```
1214
1214
0 commit comments