Skip to content

Instantly share code, notes, and snippets.

@Alexisvt
Created February 10, 2023 02:21
Show Gist options
  • Save Alexisvt/b7f319ddf55386f983f870ad2f06a56b to your computer and use it in GitHub Desktop.
Save Alexisvt/b7f319ddf55386f983f870ad2f06a56b to your computer and use it in GitHub Desktop.
Test utility for customize testing-library with react-query
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