From 1d0b0ab548a7ff8bdc4fc811d40ad585c99ad513 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Mon, 6 Jan 2025 09:27:52 +0100 Subject: [PATCH] Fix unit tests using the dummy router --- frontend/src/test-utils/router.tsx | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/frontend/src/test-utils/router.tsx b/frontend/src/test-utils/router.tsx index 4426bf7c4..da9ca99ff 100644 --- a/frontend/src/test-utils/router.tsx +++ b/frontend/src/test-utils/router.tsx @@ -10,19 +10,40 @@ import { createRootRoute, createRoute, createRouter, + matchContext, + useRouterState, } from "@tanstack/react-router"; const rootRoute = createRootRoute(); -const index = createRoute({ getParentRoute: () => rootRoute, path: "/" }); +const index = createRoute({ + getParentRoute: () => rootRoute, + path: "/", + component: () => null, +}); const router = createRouter({ history: createMemoryHistory(), routeTree: rootRoute.addChildren([index]), }); +router.load(); + +const InnerProvider: React.FC = ({ children }) => { + const matchId = useRouterState({ + select: (s) => { + return s.matches[0]?.id; + }, + }); + + return ( + {children} + ); +}; export const DummyRouter: React.FC = ({ children, }) => ( /** @ts-expect-error: The router we pass doesn't match the "real" router, which is fine for tests */ - {children} + + {children} + );