Skip to content

Commit 09fec84

Browse files
docs: elaboration for resetModules (#3059)
Co-authored-by: Vladimir <sleuths.slews0s@icloud.com>
1 parent 9dc6929 commit 09fec84

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

docs/api/vi.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,23 +291,24 @@ test('importing the next module imports mocked one', async () => {
291291

292292
- **Type**: `() => Vitest`
293293

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.
295295

296296
```ts
297297
import { vi } from 'vitest'
298+
import { data } from './data.js' // Will not get reevaluated beforeEach test
298299
299-
beforeAll(() => {
300+
beforeEach(() => {
300301
vi.resetModules()
301302
})
302303

303304
test('change state', async () => {
304-
const mod = await import('./some/path')
305+
const mod = await import('./some/path.js') // Will get reevaluated
305306
mod.changeLocalState('new value')
306307
expect(mod.getLocalState()).toBe('new value')
307308
})
308309

309310
test('module has old state', async () => {
310-
const mod = await import('./some/path')
311+
const mod = await import('./some/path.js') // Will get reevaluated
311312
expect(mod.getLocalState()).toBe('old value')
312313
})
313314
```

0 commit comments

Comments
 (0)