chore: clean .gitignore cache
This commit is contained in:
34
frontend/src/test-utils/renderWithQueryClient.tsx
Normal file
34
frontend/src/test-utils/renderWithQueryClient.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { QueryClient, QueryClientProvider, QueryClientConfig } from '@tanstack/react-query'
|
||||
import { ReactNode } from 'react'
|
||||
import { MemoryRouter, MemoryRouterProps } from 'react-router-dom'
|
||||
import { render } from '@testing-library/react'
|
||||
|
||||
const defaultConfig: QueryClientConfig = {
|
||||
defaultOptions: {
|
||||
queries: { retry: false, refetchOnWindowFocus: false },
|
||||
mutations: { retry: false },
|
||||
},
|
||||
}
|
||||
|
||||
export const createTestQueryClient = (config: QueryClientConfig = defaultConfig) => new QueryClient(config)
|
||||
|
||||
interface RenderOptions {
|
||||
client?: QueryClient
|
||||
routeEntries?: MemoryRouterProps['initialEntries']
|
||||
}
|
||||
|
||||
export const renderWithQueryClient = (ui: ReactNode, options: RenderOptions = {}) => {
|
||||
const queryClient = options.client ?? createTestQueryClient()
|
||||
const routeEntries = options.routeEntries ?? ['/']
|
||||
|
||||
const wrapper = ({ children }: { children: ReactNode }) => (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<MemoryRouter initialEntries={routeEntries}>{children}</MemoryRouter>
|
||||
</QueryClientProvider>
|
||||
)
|
||||
|
||||
return {
|
||||
queryClient,
|
||||
...render(<>{ui}</>, { wrapper }),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user