Open History to see the last commit
1import { act } from '@testing-library/react'
2β
3import { QueryClient, QueryClientConfig } from '@tanstack/query-core'
4β
5export function createQueryClient(config?: QueryClientConfig): QueryClient {
6 jest.spyOn(console, 'error').mockImplementation(() => undefined)
7 return new QueryClient({ logger: mockLogger, ...config })
8}
9β
10export const mockLogger = {
11 log: jest.fn(),
12 warn: jest.fn(),
13 error: jest.fn(),
14}
15β
16let queryKeyCount = 0
17export function queryKey(): Array<string> {
18 queryKeyCount++
19 return [`query_${queryKeyCount}`]
20}
21β
22export function sleep(timeout: number): Promise<void> {
23 return new Promise((resolve, _reject) => {
24 setTimeout(resolve, timeout)
25 })
26}
27β
28export function setActTimeout(fn: () => void, ms?: number) {
29 return setTimeout(() => {
30 act(() => {
31 fn()
32 })
33 }, ms)
34}