Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for importing itself inside __mocks__ folder
- Loading branch information
1 parent
58c188a
commit 5f8b525
Showing
4 changed files
with
48 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,14 @@ | ||
import actualCreate from 'zustand' | ||
|
||
// a variable to hold reset functions for all stores declared in the app | ||
const storeResetFns = new Set() | ||
|
||
// when creating a store, we get its initial state, create a reset function and add it in the set | ||
const create = vi.fn((createState) => { | ||
const store = actualCreate(createState) | ||
const initialState = store.getState() | ||
storeResetFns.add(() => store.setState(initialState, true)) | ||
return store | ||
}) | ||
|
||
export default create |
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,9 @@ | ||
import zustand from 'zustand' | ||
|
||
vi.mock('zustand') | ||
|
||
describe('zustand didn\'t go into an infinite loop', () => { | ||
test('zustand is mocked', () => { | ||
expect(vi.isMockFunction(zustand)).toBe(true) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.