Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: clear mock from callstack, if mocked with factory (#1276)
* fix: clear mock from callstack, if mocked with factory * test: fix test for zustand
- Loading branch information
1 parent
9695c6c
commit 7459ff8
Showing
4 changed files
with
16 additions
and
6 deletions.
There are no files selected for viewing
5 changes: 0 additions & 5 deletions
5
examples/mocks/src/zustand.ts → examples/mocks/__mocks__/zustand.ts
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,5 @@ | ||
import zustand from 'zustand' | ||
|
||
export const magic = () => { | ||
return zustand() | ||
} |
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,9 +1,16 @@ | ||
import zustand from 'zustand' | ||
import { magic } from '../src/zustand-magic' | ||
|
||
vi.mock('zustand') | ||
|
||
describe('zustand didn\'t go into an infinite loop', () => { | ||
test('zustand is mocked', () => { | ||
expect(vi.isMockFunction(zustand)).toBe(true) | ||
}) | ||
|
||
test('magic calls zustand', () => { | ||
const store = magic() | ||
expect(zustand).toHaveBeenCalled() | ||
expect(store).toBeTypeOf('function') | ||
}) | ||
}) |
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