-
-
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: don't hang when mocking module with circular dependency (#2572)
- Loading branch information
1 parent
9f41edd
commit c479d9c
Showing
4 changed files
with
20 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import b from './export-default-circle-index' | ||
|
||
export default function () { | ||
return b() | ||
} |
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,5 @@ | ||
import b from './export-default-circle-b' | ||
|
||
export default function () { | ||
return b() | ||
} |
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 |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import { expect, test, vi } from 'vitest' | ||
import { main } from '../src/main.js' | ||
import x from '../src/export-default-circle-index' | ||
|
||
vi.mock('../src/A', async () => ({ | ||
...(await vi.importActual<any>('../src/A')), | ||
funcA: () => 'mockedA', | ||
})) | ||
|
||
test('main', () => { | ||
vi.mock('../src/export-default-circle-b') | ||
|
||
test('can import actual inside mock factory', () => { | ||
expect(main()).toBe('mockedA') | ||
}) | ||
|
||
test('can mock a circular dependency', () => { | ||
expect(x()).toBe(undefined) | ||
}) |
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