From 09f5e36955a567bc1fe3c7f25c8200d64691e1bb Mon Sep 17 00:00:00 2001 From: James Brooks Date: Tue, 8 Jul 2025 15:37:18 +0100 Subject: [PATCH] Fix duplicate slash in `renderInTestApp` routing Signed-off-by: James Brooks --- .changeset/yellow-spies-rescue.md | 5 +++++ .../src/app/renderInTestApp.test.tsx | 15 +++++++++++++++ .../src/app/renderInTestApp.tsx | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .changeset/yellow-spies-rescue.md diff --git a/.changeset/yellow-spies-rescue.md b/.changeset/yellow-spies-rescue.md new file mode 100644 index 0000000000..c34f916e5b --- /dev/null +++ b/.changeset/yellow-spies-rescue.md @@ -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. diff --git a/packages/frontend-test-utils/src/app/renderInTestApp.test.tsx b/packages/frontend-test-utils/src/app/renderInTestApp.test.tsx index cee6273cb1..8e1b1e1ea0 100644 --- a/packages/frontend-test-utils/src/app/renderInTestApp.test.tsx +++ b/packages/frontend-test-utils/src/app/renderInTestApp.test.tsx @@ -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( + + Index Page} /> + Second Page} /> + , + { + initialRouteEntries: ['/second-page'], + }, + ); + + expect(screen.getByText('Second Page')).toBeInTheDocument(); + }); }); diff --git a/packages/frontend-test-utils/src/app/renderInTestApp.tsx b/packages/frontend-test-utils/src/app/renderInTestApp.tsx index d4010a92ad..2e940e83bb 100644 --- a/packages/frontend-test-utils/src/app/renderInTestApp.tsx +++ b/packages/frontend-test-utils/src/app/renderInTestApp.tsx @@ -154,7 +154,7 @@ export function renderInTestApp( factory: () => { return [ coreExtensionData.reactElement(element), - coreExtensionData.routePath('/'), + coreExtensionData.routePath(''), ]; }, }),