diff --git a/packages/core-compat-api/src/collectLegacyRoutes.test.tsx b/packages/core-compat-api/src/collectLegacyRoutes.test.tsx index c8d3822ae7..2c8288b878 100644 --- a/packages/core-compat-api/src/collectLegacyRoutes.test.tsx +++ b/packages/core-compat-api/src/collectLegacyRoutes.test.tsx @@ -27,7 +27,7 @@ import { PuppetDbPage } from '@backstage/plugin-puppetdb'; import { StackstormPage } from '@backstage/plugin-stackstorm'; import { ScoreBoardPage } from '@oriflame/backstage-plugin-score-card'; import React, { Fragment } from 'react'; -import { Route, Routes } from 'react-router-dom'; +import { Navigate, Route, Routes } from 'react-router-dom'; import { collectLegacyRoutes } from './collectLegacyRoutes'; // eslint-disable-next-line @backstage/no-relative-monorepo-imports @@ -290,9 +290,9 @@ describe('collectLegacyRoutes', () => { name: 'Test', mountPoint: routeRef, component: async () => () => { - const app = useApp(); - return
plugins: {app.getPlugins().map(p => p.getId())}
; - }), + const app = useApp(); + return
plugins: {app.getPlugins().map(p => p.getId())}
; + }, }), ); @@ -304,7 +304,36 @@ describe('collectLegacyRoutes', () => {
, ), - ).toThrow(/Invalid { + const plugin = createPlugin({ + id: 'test', + }); + const routeRef = createRouteRef({ id: 'test' }); + const Page = plugin.provide( + createRoutableExtension({ + name: 'Test', + mountPoint: routeRef, + component: async () => () => { + const app = useApp(); + return
plugins: {app.getPlugins().map(p => p.getId())}
; + }, + }), + ); + + expect(() => + collectLegacyRoutes( + + } />a string + , + ), + ).toThrow( + /Invalid element inside FlatRoutes, expected Route but found element of type string./, + ); }); it('should throw if has no path', async () => { @@ -330,6 +359,18 @@ describe('collectLegacyRoutes', () => { } /> , ), - ).toThrow(/ element with invalid path/); + ).toThrow(/Route element inside FlatRoutes had no path prop value given/); + }); + + it('should throw if element cannot be converted', async () => { + expect(() => + collectLegacyRoutes( + + } /> + , + ), + ).toThrow( + /Route with path undefined has en element that can not be converted/, + ); }); });