File tree Expand file tree Collapse file tree 4 files changed +12
-12
lines changed Expand file tree Collapse file tree 4 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -22,30 +22,30 @@ function purchase() {
2222
2323describe (' purchasing flow' , () => {
2424 beforeEach (() => {
25- // tell vitest we use mocked time
25+ // 告诉 vitest 我们使用模拟时间
2626 vi .useFakeTimers ()
2727 })
2828
2929 afterEach (() => {
30- // restoring date after each test run
30+ // 在每次测试运行后恢复日期
3131 vi .useRealTimers ()
3232 })
3333
3434 it (' allows purchases within business hours' , () => {
35- // set hour within business hours
35+ // 设置在营业时间内的小时数
3636 const date = new Date (2000 , 1 , 1 , 13 )
3737 vi .setSystemTime (date)
3838
39- // access Date.now() will result in the date set above
39+ // 访问 ` Date.now()` 将会返回上面设置的日期
4040 expect (purchase ()).toEqual ({ message: ' Success' })
4141 })
4242
4343 it (' disallows purchases outside of business hours' , () => {
44- // set hour outside business hours
44+ // 设置在营业时间外的小时数
4545 const date = new Date (2000 , 1 , 1 , 19 )
4646 vi .setSystemTime (date)
4747
48- // access Date.now() will result in the date set above
48+ // 访问 ` Date.now()` 将会返回上面设置的日期
4949 expect (purchase ()).toEqual ({ message: ' Error' })
5050 })
5151})
Original file line number Diff line number Diff line change @@ -10,17 +10,17 @@ Vitest 没有开箱即用地提供任何文件系统模拟 API。你可以使用
1010
1111::: code-group
1212``` ts [__mocks__/fs.cjs]
13- // we can also use `import`, but then
14- // every export should be explicitly defined
13+ // 我们可以使用 `import`,但是那样的话
14+ // 每个导出都需要明确定义
1515
1616const { fs } = require (' memfs' )
1717
1818module .exports = fs
1919```
2020
2121``` ts [__mocks__/fs/promises.cjs]
22- // we can also use `import`, but then
23- // every export should be explicitly defined
22+ // 我们可以使用 `import`,但是那样的话
23+ // 每个导出都需要明确定义
2424
2525const { fs } = require (' memfs' )
2626
Original file line number Diff line number Diff line change @@ -16,5 +16,5 @@ const IntersectionObserverMock = vi.fn(() => ({
1616
1717vi .stubGlobal (' IntersectionObserver' , IntersectionObserverMock )
1818
19- // now you can access it as `IntersectionObserver` or `window.IntersectionObserver`
19+ // 现在你可以通过 `IntersectionObserver` 或 `window.IntersectionObserver` 来访问它
2020```
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ describe('delayed execution', () => {
3333 })
3434 it (' should not execute the function' , () => {
3535 executeAfterTwoHours (mock)
36- // advancing by 2ms won't trigger the func
36+ // 前进2毫秒不会触发该函数
3737 vi .advanceTimersByTime (2 )
3838 expect (mock).not .toHaveBeenCalled ()
3939 })
You can’t perform that action at this time.
0 commit comments