Last active
May 28, 2025 13:47
-
-
Save DZuz14/477ac245eb95865319cacc0450693129 to your computer and use it in GitHub Desktop.
Vitest Zustand mock store
This file contains hidden or 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
import { mockSong } from '@/data/song'; | |
import { useCadenceStore } from '@/store/cadence'; | |
import { CadenceStore } from '@/types/cadence'; | |
import '@testing-library/jest-dom'; | |
import * as matchers from '@testing-library/jest-dom/matchers'; | |
import { expect, vi } from 'vitest'; | |
expect.extend(matchers); | |
vi.mock('@/store/cadence', () => ({ | |
useCadenceStore: vi.fn(), | |
})); | |
const useCadenceStoreMock = vi.mocked(useCadenceStore); | |
export const mockUseCadenceStore = (overrides: Partial<CadenceStore> = {}) => { | |
useCadenceStoreMock.mockReturnValue({ | |
song: mockSong, | |
setSong: vi.fn(), | |
handleCellChange: vi.fn(), | |
...overrides, | |
}); | |
}; | |
beforeEach(() => { | |
mockUseCadenceStore(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment