Last active
April 3, 2024 09:24
-
-
Save SpadarShut/64993d0c3578154fe3733d155df19b2b to your computer and use it in GitHub Desktop.
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 { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | |
import { render } from "@testing-library/react-native"; | |
import { ReactElement, ReactNode } from "react"; | |
import { AppContexts } from "../../App"; | |
const createTestQueryClient = () => | |
new QueryClient({ | |
defaultOptions: { | |
queries: { | |
retry: false, | |
gcTime: 0, | |
}, | |
mutations: { | |
retry: false, | |
gcTime: 0, | |
}, | |
}, | |
}); | |
export function createWrapper() { | |
const testQueryClient = createTestQueryClient(); | |
return function QueryClientWrapper(props: { children: ReactNode }) { | |
return ( | |
<QueryClientProvider client={testQueryClient}> | |
{props.children} | |
</QueryClientProvider> | |
); | |
}; | |
} | |
export const renderWithContexts: typeof render = ( | |
ui: ReactElement, | |
options, | |
) => { | |
const testQueryClient = createTestQueryClient(); | |
const { rerender, ...result } = render( | |
<AppContexts reactQueryClient={testQueryClient}>{ui}</AppContexts>, | |
options, | |
); | |
return { | |
...result, | |
rerender: (rerenderUi: ReactElement) => | |
rerender( | |
<QueryClientProvider client={testQueryClient}> | |
{rerenderUi} | |
</QueryClientProvider>, | |
), | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment