2021-11-03 10:41:59 +00:00
|
|
|
import '@testing-library/jest-dom';
|
|
|
|
|
|
|
|
import { render, RenderOptions } from '@testing-library/react';
|
|
|
|
import { UIRouter, pushStateLocationPlugin } from '@uirouter/react';
|
|
|
|
import { PropsWithChildren, ReactElement } from 'react';
|
2022-01-05 16:28:56 +00:00
|
|
|
import { QueryClient, QueryClientProvider } from 'react-query';
|
2021-11-03 10:41:59 +00:00
|
|
|
|
|
|
|
function Provider({ children }: PropsWithChildren<unknown>) {
|
|
|
|
return <UIRouter plugins={[pushStateLocationPlugin]}>{children}</UIRouter>;
|
|
|
|
}
|
|
|
|
|
|
|
|
function customRender(ui: ReactElement, options?: RenderOptions) {
|
|
|
|
return render(ui, { wrapper: Provider, ...options });
|
|
|
|
}
|
|
|
|
|
|
|
|
// re-export everything
|
|
|
|
export * from '@testing-library/react';
|
|
|
|
|
|
|
|
// override render method
|
|
|
|
export { customRender as render };
|
2022-01-05 16:28:56 +00:00
|
|
|
|
|
|
|
export function renderWithQueryClient(ui: React.ReactElement) {
|
|
|
|
const testQueryClient = new QueryClient({
|
|
|
|
defaultOptions: { queries: { retry: false } },
|
|
|
|
});
|
|
|
|
const { rerender, ...result } = customRender(
|
|
|
|
<QueryClientProvider client={testQueryClient}>{ui}</QueryClientProvider>
|
|
|
|
);
|
|
|
|
return {
|
|
|
|
...result,
|
|
|
|
rerender: (rerenderUi: React.ReactElement) =>
|
|
|
|
rerender(
|
|
|
|
<QueryClientProvider client={testQueryClient}>
|
|
|
|
{rerenderUi}
|
|
|
|
</QueryClientProvider>
|
|
|
|
),
|
|
|
|
};
|
|
|
|
}
|