ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

36 lines
905 B

  1. import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
  2. import { render } from '@testing-library/react'
  3. import { HelmetProvider } from 'react-helmet-async'
  4. import { MemoryRouter } from 'react-router-dom'
  5. import type { ReactElement, ReactNode } from 'react'
  6. type Options = {
  7. route?: string
  8. }
  9. export const renderWithProviders = (
  10. ui: ReactElement,
  11. options: Options = {},
  12. ) => {
  13. const queryClient = new QueryClient ({
  14. defaultOptions: {
  15. queries: { retry: false },
  16. },
  17. })
  18. const Wrapper = ({ children }: { children: ReactNode }) => (
  19. <QueryClientProvider client={queryClient}>
  20. <HelmetProvider>
  21. <MemoryRouter initialEntries={[options.route ?? '/']}>
  22. {children}
  23. </MemoryRouter>
  24. </HelmetProvider>
  25. </QueryClientProvider>)
  26. return {
  27. queryClient,
  28. ...render (ui, { wrapper: Wrapper }),
  29. }
  30. }