Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 1x 1x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x | import type { PropsWithChildren, ReactElement } from "react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { render, type RenderOptions } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
type ExtendedRenderOptions = RenderOptions & {
route?: string;
};
export function renderWithProviders(
ui: ReactElement,
options: ExtendedRenderOptions = {},
) {
const { route = "/", ...renderOptions } = options;
const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: false,
refetchOnWindowFocus: false,
},
mutations: {
retry: false,
},
},
});
function Wrapper({ children }: PropsWithChildren): ReactElement {
return (
<MemoryRouter initialEntries={[route]}>
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
</MemoryRouter>
);
}
return {
queryClient,
...render(ui, { wrapper: Wrapper, ...renderOptions }),
};
}
|