MCPcopy
hub / github.com/TanStack/router / createTestRouter

Function createTestRouter

packages/react-router/tests/ClientOnly.test.tsx:19–53  ·  view source on GitHub ↗
(opts: { isServer: boolean })

Source from the content-addressed store, hash-verified

17})
18
19function createTestRouter(opts: { isServer: boolean }) {
20 const history = createMemoryHistory({ initialEntries: ['/'] })
21
22 const rootRoute = createRootRoute({})
23
24 const indexRoute = createRoute({
25 getParentRoute: () => rootRoute,
26 path: '/',
27 component: () => (
28 <div>
29 <p>Index Route</p>
30 <ClientOnly fallback={<div data-testid="loading">Loading...</div>}>
31 <div data-testid="client-only-content">Client Only Content</div>
32 </ClientOnly>
33 </div>
34 ),
35 })
36 const otherRoute = createRoute({
37 getParentRoute: () => rootRoute,
38 path: '/other',
39 component: () => (
40 <div>
41 <p data-testid="other-route">Other Route</p>
42 </div>
43 ),
44 })
45
46 const routeTree = rootRoute.addChildren([indexRoute, otherRoute])
47 const router = createRouter({ routeTree, history, ...opts })
48
49 return {
50 router,
51 routes: { indexRoute },
52 }
53}
54
55describe('ClientOnly', () => {
56 it('should render fallback during SSR', async () => {

Callers 1

Calls 4

createMemoryHistoryFunction · 0.90
createRootRouteFunction · 0.90
createRouteFunction · 0.90
createRouterFunction · 0.90

Tested by

no test coverage detected