You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/vi.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -291,23 +291,24 @@ test('importing the next module imports mocked one', async () => {
291
291
292
292
-**Type**: `() => Vitest`
293
293
294
-
Resets modules registry by clearing cache of all modules. Might be useful to isolate modules where local state conflicts between tests.
294
+
Resets modules registry by clearing cache of all modules. This allows modules to be reevaluated when reimported. Top-level imports cannot be reevaluated. Might be useful to isolate modules where local state conflicts between tests.
295
295
296
296
```ts
297
297
import { vi } from'vitest'
298
+
import { data } from'./data.js'// Will not get reevaluated beforeEach test
298
299
299
-
beforeAll(() => {
300
+
beforeEach(() => {
300
301
vi.resetModules()
301
302
})
302
303
303
304
test('change state', async () => {
304
-
const mod =awaitimport('./some/path')
305
+
const mod =awaitimport('./some/path.js') // Will get reevaluated
305
306
mod.changeLocalState('new value')
306
307
expect(mod.getLocalState()).toBe('new value')
307
308
})
308
309
309
310
test('module has old state', async () => {
310
-
const mod =awaitimport('./some/path')
311
+
const mod =awaitimport('./some/path.js') // Will get reevaluated
0 commit comments