Fix duplicate slash in renderInTestApp routing

Signed-off-by: James Brooks <jamesbrooks@spotify.com>
This commit is contained in:
James Brooks
2025-07-08 15:37:18 +01:00
parent 21e076adea
commit 09f5e36955
3 changed files with 21 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/frontend-test-utils': patch
---
Update route path for index route in `renderInTestApp` util to fix duplicate slash and ensure any nested routing behaves correctly.
@@ -21,6 +21,7 @@ import {
TestApiProvider,
} from '@backstage/frontend-test-utils';
import { analyticsApiRef, useAnalytics } from '@backstage/frontend-plugin-api';
import { Routes, Route } from 'react-router-dom';
import { renderInTestApp } from './renderInTestApp';
describe('renderInTestApp', () => {
@@ -65,4 +66,18 @@ describe('renderInTestApp', () => {
]),
);
});
it('should support setting different locations in the history stack', async () => {
renderInTestApp(
<Routes>
<Route path="/" element={<h1>Index Page</h1>} />
<Route path="/second-page" element={<h1>Second Page</h1>} />
</Routes>,
{
initialRouteEntries: ['/second-page'],
},
);
expect(screen.getByText('Second Page')).toBeInTheDocument();
});
});
@@ -154,7 +154,7 @@ export function renderInTestApp(
factory: () => {
return [
coreExtensionData.reactElement(element),
coreExtensionData.routePath('/'),
coreExtensionData.routePath(''),
];
},
}),