(args?: {
props?: RoutesTestStubProps
entries?: StubRouteEntry[]
i18n?: {
lng?: Language
ns?: Namespace | Namespace[]
}
})
| 9 | export type StubRouteEntry = Parameters<typeof createRoutesStub>[0][0] |
| 10 | |
| 11 | const renderStub = async (args?: { |
| 12 | props?: RoutesTestStubProps |
| 13 | entries?: StubRouteEntry[] |
| 14 | i18n?: { |
| 15 | lng?: Language |
| 16 | ns?: Namespace | Namespace[] |
| 17 | } |
| 18 | }) => { |
| 19 | const instance = createInstance() |
| 20 | // Initialize the i18next instance |
| 21 | await instance |
| 22 | .use(initReactI18next) // Tell our instance to use react-i18next |
| 23 | .init({ |
| 24 | ...i18n, // spread the configuration |
| 25 | lng: args?.i18n?.lng ?? "en", // The locale can be set per test or defaults to english |
| 26 | ns: args?.i18n?.ns ?? "common", // The namespaces can be set in the test or defaults to common |
| 27 | resources, |
| 28 | }) |
| 29 | |
| 30 | // We create the entries array to be rendered by react-router |
| 31 | const entries: StubRouteEntry[] = [ |
| 32 | { |
| 33 | id: "root", |
| 34 | path: "/", |
| 35 | children: args?.entries ?? [], |
| 36 | Component: () => ( |
| 37 | <div data-testid="root"> |
| 38 | <I18nextProvider i18n={instance}> |
| 39 | <Outlet /> |
| 40 | </I18nextProvider> |
| 41 | </div> |
| 42 | ), |
| 43 | }, |
| 44 | ] |
| 45 | // We generate the props to be passed into the react-router stub |
| 46 | const props: RoutesTestStubProps = { |
| 47 | ...args?.props, |
| 48 | initialEntries: args?.props?.initialEntries ?? ["/"], |
| 49 | } |
| 50 | // We generate the stub using the entries and props |
| 51 | const Stub = createRoutesStub(entries) |
| 52 | // We render the container so it can be used in tests |
| 53 | const renderedScreen = render(<Stub {...props} />) |
| 54 | |
| 55 | return renderedScreen |
| 56 | } |
| 57 | |
| 58 | const renderHook = renderReactHook |
| 59 |
no outgoing calls
no test coverage detected
searching dependent graphs…