-
-
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(vitest): correctly hoist
vi.hoisted
if assigned (#4285)
- Loading branch information
1 parent
eac7776
commit ff93a57
Showing
4 changed files
with
42 additions
and
1 deletion.
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,2 @@ | ||
// @ts-expect-error not typed global | ||
export const value = globalThis.someGlobalValue |
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,19 @@ | ||
// this test checks only vi.hoisted because vi.mock affects the regexp to find this | ||
|
||
import { afterAll, expect, it, vi } from 'vitest' | ||
import { value } from '../src/rely-on-hoisted' | ||
|
||
const globalValue = await vi.hoisted(async () => { | ||
// @ts-expect-error not typed global | ||
globalThis.someGlobalValue = 'globalValue' | ||
return 'globalValue' | ||
}) | ||
|
||
afterAll(() => { | ||
// @ts-expect-error not typed global | ||
delete globalThis.someGlobalValue | ||
}) | ||
|
||
it('imported value is equal to returned from hoisted', () => { | ||
expect(value).toBe(globalValue) | ||
}) |
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,19 @@ | ||
// this test checks only vi.hoisted because vi.mock affects the regexp to find this | ||
|
||
import { afterAll, expect, it, vi } from 'vitest' | ||
import { value } from '../src/rely-on-hoisted' | ||
|
||
const globalValue = vi.hoisted(() => { | ||
// @ts-expect-error not typed global | ||
globalThis.someGlobalValue = 'globalValue' | ||
return 'globalValue' | ||
}) | ||
|
||
afterAll(() => { | ||
// @ts-expect-error not typed global | ||
delete globalThis.someGlobalValue | ||
}) | ||
|
||
it('imported value is equal to returned from hoisted', () => { | ||
expect(value).toBe(globalValue) | ||
}) |