Created
February 10, 2023 02:21
-
-
Save Alexisvt/b7f319ddf55386f983f870ad2f06a56b to your computer and use it in GitHub Desktop.
Test utility for customize testing-library with react-query
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 as rtlRender } from '@testing-library/react' | |
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |
function render(ui: React.ReactElement, { ...renderOptions } = {} as any) { | |
const queryClient = new QueryClient() | |
const Wrapper = ({ children }: { children: React.ReactNode }) => ( | |
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | |
) | |
return rtlRender(ui, { wrapper: Wrapper, ...renderOptions }) | |
} | |
// re-export everything | |
export * from '@testing-library/react' | |
// override render method | |
export { render } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment