-
Notifications
You must be signed in to change notification settings - Fork 8
/
test-utils.tsx
42 lines (37 loc) · 1.2 KB
/
test-utils.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import React from 'react'
import { BrowserRouter } from 'react-router-dom'
import { render } from '@testing-library/react'
import { QueryClient, QueryClientProvider } from 'react-query'
import type { FetchMockStatic } from 'fetch-mock'
import { routes } from './routes'
const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: false,
},
},
})
const customRender = (ui: React.ReactElement) =>
render(ui, {
wrapper: ({ children }) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
),
})
export function renderAppAt(url: string) {
window.history.pushState({}, 'Test page', url)
return render(routes, {
wrapper: ({ children }) => (
<BrowserRouter>
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
</BrowserRouter>
),
})
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const lastPostBody = (mock: FetchMockStatic): any =>
JSON.parse(mock.lastOptions(undefined, 'POST')?.body as unknown as string)
export * from '@testing-library/react'
export { default as userEvent } from '@testing-library/user-event'
export { customRender as render }