Skip to content

Commit

Permalink
fix: use generatePath in testUtils
Browse files Browse the repository at this point in the history
to support optional parameters in test paths
  • Loading branch information
pomegranited committed Dec 18, 2024
1 parent b110b6b commit aa25827
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/testUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { render, type RenderResult } from '@testing-library/react';
import MockAdapter from 'axios-mock-adapter';
import {
generatePath,
MemoryRouter,
MemoryRouterProps,
Route,
Expand Down Expand Up @@ -94,10 +95,7 @@ const RouterAndRoute: React.FC<RouteOptions> = ({
const newRouterProps = { ...routerProps };
if (!routerProps.initialEntries) {
// Substitute the params into the URL so '/library/:libraryId' becomes '/library/lib:org:123'
let pathWithParams = path;
for (const [key, value] of Object.entries(params)) {
pathWithParams = pathWithParams.replaceAll(`:${key}`, value);
}
let pathWithParams = generatePath(path, params);
if (pathWithParams.endsWith('/*')) {
// Some routes (that contain child routes) need to end with /* in the <Route> but not in the router
pathWithParams = pathWithParams.substring(0, pathWithParams.length - 1);
Expand Down

0 comments on commit aa25827

Please sign in to comment.