UNPKG

3.17 kBTypeScriptView Raw
1
2import { InitialEntry } from "../../router/history.js";
3import { ActionFunction, IndexRouteObject, LoaderFunction, NonIndexRouteObject, RouterContextProvider } from "../../router/utils.js";
4import { HydrationState } from "../../router/router.js";
5import { LinksFunction, MetaFunction } from "./routeModules.js";
6import { FutureConfig } from "./entry.js";
7import * as React$1 from "react";
8
9//#region lib/dom/ssr/routes-test-stub.d.ts
10interface 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}
20interface StubIndexRouteObject extends Omit<IndexRouteObject, "Component" | "HydrateFallback" | "ErrorBoundary" | "loader" | "action" | "element" | "errorElement" | "children">, StubRouteExtensions {}
21interface StubNonIndexRouteObject extends Omit<NonIndexRouteObject, "Component" | "HydrateFallback" | "ErrorBoundary" | "loader" | "action" | "element" | "errorElement" | "children">, StubRouteExtensions {}
22type StubRouteObject = StubIndexRouteObject | StubNonIndexRouteObject;
23interface 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 // start at "/events/123"
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 */
68declare function createRoutesStub(routes: StubRouteObject[], _context?: RouterContextProvider): ({
69 initialEntries,
70 initialIndex,
71 hydrationData,
72 future
73}: RoutesTestStubProps) => React$1.JSX.Element;
74//#endregion
75export { RoutesTestStubProps, createRoutesStub };
\No newline at end of file