| 1 |
|
| 2 | import { InitialEntry } from "../../router/history.js";
|
| 3 | import { ActionFunction, IndexRouteObject, LoaderFunction, NonIndexRouteObject, RouterContextProvider } from "../../router/utils.js";
|
| 4 | import { HydrationState } from "../../router/router.js";
|
| 5 | import { LinksFunction, MetaFunction } from "./routeModules.js";
|
| 6 | import { FutureConfig } from "./entry.js";
|
| 7 | import * as React$1 from "react";
|
| 8 |
|
| 9 |
|
| 10 | interface StubRouteExtensions {
|
| 11 | Component?: React$1.ComponentType<any>;
|
| 12 | HydrateFallback?: React$1.ComponentType<any>;
|
| 13 | ErrorBoundary?: React$1.ComponentType<any>;
|
| 14 | loader?: LoaderFunction;
|
| 15 | action?: ActionFunction;
|
| 16 | children?: StubRouteObject[];
|
| 17 | meta?: MetaFunction;
|
| 18 | links?: LinksFunction;
|
| 19 | }
|
| 20 | interface StubIndexRouteObject extends Omit<IndexRouteObject, "Component" | "HydrateFallback" | "ErrorBoundary" | "loader" | "action" | "element" | "errorElement" | "children">, StubRouteExtensions {}
|
| 21 | interface StubNonIndexRouteObject extends Omit<NonIndexRouteObject, "Component" | "HydrateFallback" | "ErrorBoundary" | "loader" | "action" | "element" | "errorElement" | "children">, StubRouteExtensions {}
|
| 22 | type StubRouteObject = StubIndexRouteObject | StubNonIndexRouteObject;
|
| 23 | interface RoutesTestStubProps {
|
| 24 | |
| 25 | * The initial entries in the history stack. This allows you to start a test with
|
| 26 | * multiple locations already in the history stack (for testing a back navigation, etc.)
|
| 27 | * The test will default to the last entry in initialEntries if no initialIndex is provided.
|
| 28 | * e.g. initialEntries={["/home", "/about", "/contact"]}
|
| 29 | */
|
| 30 | initialEntries?: InitialEntry[];
|
| 31 | |
| 32 | * The initial index in the history stack to render. This allows you to start a test at a specific entry.
|
| 33 | * It defaults to the last entry in initialEntries.
|
| 34 | * e.g.
|
| 35 | * initialEntries: ["/", "/events/123"]
|
| 36 | * initialIndex: 1
|
| 37 | */
|
| 38 | initialIndex?: number;
|
| 39 | |
| 40 | * Used to set the route's initial loader and action data.
|
| 41 | * e.g. hydrationData={{
|
| 42 | * loaderData: { "/contact": { locale: "en-US" } },
|
| 43 | * actionData: { "/login": { errors: { email: "invalid email" } }}
|
| 44 | * }}
|
| 45 | */
|
| 46 | hydrationData?: HydrationState;
|
| 47 | |
| 48 | * Future flags mimicking the settings in react-router.config.ts
|
| 49 | */
|
| 50 | future?: Partial<FutureConfig>;
|
| 51 | }
|
| 52 | |
| 53 | * Creates a React component that renders the provided routes in a test-friendly
|
| 54 | * React Router context.
|
| 55 | *
|
| 56 | * Use this to unit test components that rely on router context, such as
|
| 57 | * `loaderData`, `actionData`, and route matches.
|
| 58 | *
|
| 59 | * @public
|
| 60 | * @category Utils
|
| 61 | * @mode framework
|
| 62 | * @mode data
|
| 63 | * @param routes The route objects to render in the test router.
|
| 64 | * @param _context An optional {@link RouterContextProvider} for supplying
|
| 65 | * application context values to route middleware, loaders, and actions.
|
| 66 | * @returns A React component that renders the test router.
|
| 67 | */
|
| 68 | declare function createRoutesStub(routes: StubRouteObject[], _context?: RouterContextProvider): ({
|
| 69 | initialEntries,
|
| 70 | initialIndex,
|
| 71 | hydrationData,
|
| 72 | future
|
| 73 | }: RoutesTestStubProps) => React$1.JSX.Element;
|
| 74 |
|
| 75 | export { RoutesTestStubProps, createRoutesStub }; |
| \ | No newline at end of file |