All files / src/test harness.tsx

100% Statements 2/2
75% Branches 3/4
100% Functions 1/1
100% Lines 2/2

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                                  38x             38x                                
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { render, type RenderResult } from "@testing-library/react";
import { ThemeProvider } from "chainr-frontend-shared";
import React from "react";
import { MemoryRouter, Route, Routes } from "react-router-dom";
 
/**
 * Render a public-site page with the providers the app gives it.
 *
 * Kept local rather than shared with fe-core's copy: the two apps wrap their
 * pages differently and `chainr-frontend-shared` is for shipped components,
 * not test scaffolding.
 */
export function renderPage(
  element: React.ReactNode,
  { path = "/", url }: { path?: string; url?: string } = {},
): RenderResult {
  const client = new QueryClient({
    defaultOptions: {
      queries: { retry: false, gcTime: 0 },
      mutations: { retry: false },
    },
  });
 
  return render(
    <QueryClientProvider client={client}>
      <ThemeProvider>
        <MemoryRouter initialEntries={[url ?? path.replace(/\/?\*$/, "")]}>
          {/* Routed pages are lazy in the app, so a test that renders one
              directly needs the same boundary the app provides. */}
          <React.Suspense fallback={null}>
            <Routes>
              <Route path={path} element={element} />
            </Routes>
          </React.Suspense>
        </MemoryRouter>
      </ThemeProvider>
    </QueryClientProvider>,
  );
}