diff --git a/.changeset/fix-test-route-matching.md b/.changeset/fix-test-route-matching.md new file mode 100644 index 0000000000..4f69688f86 --- /dev/null +++ b/.changeset/fix-test-route-matching.md @@ -0,0 +1,5 @@ +--- +'@backstage/frontend-test-utils': patch +--- + +Fixed `renderInTestApp` to set up React Router route matching when `mountedRoutes` are provided. Previously, mounted routes only fed the route resolution API for link generation (`useRouteRef`), but did not create `` elements for param extraction (`useParams`). This meant that `initialRouteEntries` had no effect on route param availability. The test element is now wrapped in `` with a `` for each mounted path, matching the behavior of the real `AppRoutes` extension. diff --git a/packages/frontend-test-utils/src/app/renderInTestApp.tsx b/packages/frontend-test-utils/src/app/renderInTestApp.tsx index 170d6d7294..07dccd9eee 100644 --- a/packages/frontend-test-utils/src/app/renderInTestApp.tsx +++ b/packages/frontend-test-utils/src/app/renderInTestApp.tsx @@ -135,6 +135,7 @@ export function renderInTestApp( output: [coreExtensionData.reactElement], factory: () => { let content: JSX.Element = element; + if (mountedPaths.length > 0) { content = ( @@ -142,13 +143,14 @@ export function renderInTestApp( ))} - + ); } + return [coreExtensionData.reactElement(content)]; }, }),