You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-07 17:03:01 +03:00
frontend: use RouterContextProvider instead of RouterProvider in tests
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import {
|
import {
|
||||||
RouterProvider,
|
RouterContextProvider,
|
||||||
createMemoryHistory,
|
createMemoryHistory,
|
||||||
createRootRoute,
|
createRootRoute,
|
||||||
createRoute,
|
createRoute,
|
||||||
@@ -22,25 +22,15 @@ import {
|
|||||||
|
|
||||||
const rootRoute = createRootRoute();
|
const rootRoute = createRootRoute();
|
||||||
const index = createRoute({ getParentRoute: () => rootRoute, path: "/" });
|
const index = createRoute({ getParentRoute: () => rootRoute, path: "/" });
|
||||||
rootRoute.addChildren([index]);
|
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createMemoryHistory(),
|
history: createMemoryHistory(),
|
||||||
routeTree: rootRoute,
|
routeTree: rootRoute.addChildren([index]),
|
||||||
});
|
});
|
||||||
|
|
||||||
const routerReady = router.load();
|
|
||||||
// Because we also use this in the stories, we need to make sure we call this only in tests
|
|
||||||
if (import.meta.vitest) {
|
|
||||||
// Make sure the router is ready before running any tests
|
|
||||||
import("vitest").then(({ beforeAll }) =>
|
|
||||||
beforeAll(async () => await routerReady),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const DummyRouter: React.FC<React.PropsWithChildren> = ({
|
export const DummyRouter: React.FC<React.PropsWithChildren> = ({
|
||||||
children,
|
children,
|
||||||
}) => (
|
}) => (
|
||||||
/** @ts-expect-error: The router we pass doesn't match the "real" router, which is fine for tests */
|
/** @ts-expect-error: The router we pass doesn't match the "real" router, which is fine for tests */
|
||||||
<RouterProvider router={router} defaultComponent={() => children} />
|
<RouterContextProvider router={router}>{children}</RouterContextProvider>
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user