-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: delete mock in moduleCache when unmock (#1947)
- Loading branch information
1 parent
55049f4
commit 03f7450
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { afterEach, beforeEach, expect, test, vi } from 'vitest' | ||
|
||
// https://github.com/vitest-dev/vitest/issues/1940 | ||
beforeEach(() => { | ||
vi.doMock('/data', () => ({ | ||
data: { | ||
state: 'STARTED', | ||
}, | ||
})) | ||
}) | ||
afterEach(() => { | ||
vi.doUnmock('/data') | ||
}) | ||
|
||
test('first import', async () => { | ||
// @ts-expect-error I know this | ||
const { data } = await import('/data') | ||
data.state = 'STOPPED' | ||
expect(data.state).toBe('STOPPED') | ||
}) | ||
|
||
test('second import should had been re-mock', async () => { | ||
// @ts-expect-error I know this | ||
const { data } = await import('/data') | ||
expect(data.state).toBe('STARTED') | ||
}) |