@@ -69,8 +69,8 @@ foo.bar() // 'Hello, mock!'
69
69
70
70
foo .bar .mockReset ()
71
71
72
- foo .bar () // undefined // [!code --]
73
- foo .bar () // 'Hello, world!' // [!code ++]
72
+ foo .bar () // undefined [!code --]
73
+ foo .bar () // 'Hello, world!' [!code ++]
74
74
```
75
75
76
76
### ` vi.spyOn ` Reuses Mock if Method is Already Mocked
@@ -81,8 +81,8 @@ Previously, Vitest would always assign a new spy when spying on an object. This
81
81
vi .spyOn (fooService , ' foo' ).mockImplementation (() => ' bar' )
82
82
vi .spyOn (fooService , ' foo' ).mockImplementation (() => ' bar' )
83
83
vi .restoreAllMocks ()
84
- vi .isMockFunction (fooService .foo ) // true // [!code --]
85
- vi .isMockFunction (fooService .foo ) // false // [!code ++]
84
+ vi .isMockFunction (fooService .foo ) // true [!code --]
85
+ vi .isMockFunction (fooService .foo ) // false [!code ++]
86
86
```
87
87
88
88
### Fake Timers Defaults
@@ -92,8 +92,8 @@ Vitest no longer provides default `fakeTimers.toFake` options. Now, Vitest will
92
92
``` ts
93
93
vi .useFakeTimers ()
94
94
95
- performance .now () // original // [!code --]
96
- performance .now () // fake // [!code ++]
95
+ performance .now () // original [!code --]
96
+ performance .now () // fake [!code ++]
97
97
```
98
98
99
99
You can revert to the previous behaviour by specifying timers when calling ` vi.useFakeTimers ` or globally in the config:
@@ -102,7 +102,15 @@ You can revert to the previous behaviour by specifying timers when calling `vi.u
102
102
export default defineConfig ({
103
103
test: {
104
104
fakeTimers: {
105
- toFake: [' setTimeout' , ' clearTimeout' , ' Date' ], // [!code ++]
105
+ toFake: [ // [!code ++]
106
+ ' setTimeout' , // [!code ++]
107
+ ' clearTimeout' , // [!code ++]
108
+ ' setInterval' , // [!code ++]
109
+ ' clearInterval' , // [!code ++]
110
+ ' setImmediate' , // [!code ++]
111
+ ' clearImmediate' , // [!code ++]
112
+ ' Date' , // [!code ++]
113
+ ] // [!code ++]
106
114
},
107
115
},
108
116
})
@@ -278,8 +286,8 @@ Previously Vitest resolved `mock.results` values if the function returned a Prom
278
286
const fn = vi .fn ().mockResolvedValueOnce (' result' )
279
287
await fn ()
280
288
281
- const result = fn .mock .results [0 ] // 'result' // [!code --]
282
- const result = fn .mock .results [0 ] // 'Promise<result>' // [!code ++]
289
+ const result = fn .mock .results [0 ] // 'result' [!code --]
290
+ const result = fn .mock .results [0 ] // 'Promise<result>' [!code ++]
283
291
284
292
const settledResult = fn .mock .settledResults [0 ] // 'result'
285
293
```
@@ -530,14 +538,7 @@ If you want to modify the object, you will use [replaceProperty API](https://jes
530
538
531
539
From Vitest v0.10.0, the callback style of declaring tests is deprecated. You can rewrite them to use ` async ` /` await ` functions, or use Promise to mimic the callback style.
532
540
533
- ```
534
- it('should work', (done) => { // [!code --]
535
- it('should work', () => new Promise(done => { // [!code ++]
536
- // ...
537
- done()
538
- }) // [!code --]
539
- })) // [!code ++]
540
- ```
541
+ <!-- @include: ./examples/promise-done.md-->
541
542
542
543
### Hooks
543
544
0 commit comments