Add changeset for renderInTestApp route matching fix
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -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 `<Route>` elements for param extraction (`useParams`). This meant that `initialRouteEntries` had no effect on route param availability. The test element is now wrapped in `<Routes>` with a `<Route>` for each mounted path, matching the behavior of the real `AppRoutes` extension.
|
||||
@@ -135,6 +135,7 @@ export function renderInTestApp<const TApiPairs extends any[] = any[]>(
|
||||
output: [coreExtensionData.reactElement],
|
||||
factory: () => {
|
||||
let content: JSX.Element = element;
|
||||
|
||||
if (mountedPaths.length > 0) {
|
||||
content = (
|
||||
<Routes>
|
||||
@@ -142,13 +143,14 @@ export function renderInTestApp<const TApiPairs extends any[] = any[]>(
|
||||
<Route
|
||||
key={path}
|
||||
path={path === '/' ? path : `${path.replace(/\/$/, '')}/*`}
|
||||
element={element}
|
||||
element={content}
|
||||
/>
|
||||
))}
|
||||
<Route path="*" element={element} />
|
||||
<Route path="*" element={content} />
|
||||
</Routes>
|
||||
);
|
||||
}
|
||||
|
||||
return [coreExtensionData.reactElement(content)];
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user