Skip to content

Instantly share code, notes, and snippets.

@SpadarShut
Last active April 3, 2024 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SpadarShut/64993d0c3578154fe3733d155df19b2b to your computer and use it in GitHub Desktop.
Save SpadarShut/64993d0c3578154fe3733d155df19b2b to your computer and use it in GitHub Desktop.
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