-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: return a disposable from doMock() #9332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,3 +30,35 @@ test('the second doMock can override the first doMock', async () => { | |||||||||||||
|
|
||||||||||||||
| expect(incrementWith20(1)).toBe(21) | ||||||||||||||
| }) | ||||||||||||||
|
|
||||||||||||||
| test.runIf(Symbol.dispose)('doMock works with using', async () => { | ||||||||||||||
| vi.doUnmock('./fixtures/increment') | ||||||||||||||
|
|
||||||||||||||
| { | ||||||||||||||
| const { increment: incrementWith1 } = await import('./fixtures/increment') | ||||||||||||||
| expect(incrementWith1(1)).toBe(2) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| { | ||||||||||||||
| using _incrementMock = vi.doMock('./fixtures/increment', () => ({ | ||||||||||||||
| increment: (num: number) => num + 10, | ||||||||||||||
| })) | ||||||||||||||
|
|
||||||||||||||
| const { increment: incrementWith10 } = await import('./fixtures/increment') | ||||||||||||||
|
|
||||||||||||||
| expect(incrementWith10(1)).toBe(11) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| { | ||||||||||||||
| const { increment: incrementWith1 } = await import('./fixtures/increment') | ||||||||||||||
| expect(incrementWith1(1)).toBe(2) | ||||||||||||||
| } | ||||||||||||||
| }) | ||||||||||||||
|
|
||||||||||||||
| test.skipIf(Symbol.dispose)('doMock works with using', async () => { | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test seems weird, because Maybe it should instead check
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had lifted the pattern from here: vitest/test/core/test/jest-mock.test.ts Lines 758 to 762 in d3afa60
I wasn't sure if vitest/test/core/test/esnext.test.ts Line 22 in e922e92
If
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, if there is no reason to test something, then don't test it |
||||||||||||||
| const _incrementMock = vi.doMock('./fixtures/increment', () => ({ | ||||||||||||||
| increment: (num: number) => num + 10, | ||||||||||||||
| })) | ||||||||||||||
|
|
||||||||||||||
| expect(_incrementMock?.[Symbol.dispose]).toBeUndefined() | ||||||||||||||
| }) | ||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.