* Try avoiding unnecessary context and just mount your component. If it works, * then you dont need anything else. * * render( ); * * If your component requires additional context you can pass it in the * options. * * To test route changes, this function returns a `router`
(ui: React.ReactElement, options: RenderOptions = {})
| 316 | * location, pass an `initialRouterConfig`. |
| 317 | */ |
| 318 | function render(ui: React.ReactElement, options: RenderOptions = {}): RenderReturn { |
| 319 | const {initialEntry, config, outletContext} = getInitialRouterConfig(options); |
| 320 | |
| 321 | const history = createMemoryHistory({ |
| 322 | initialEntries: [initialEntry], |
| 323 | }); |
| 324 | |
| 325 | const AllTheProviders = makeAllTheProviders({ |
| 326 | organization: options.organization, |
| 327 | additionalWrapper: options.additionalWrapper, |
| 328 | }); |
| 329 | |
| 330 | const memoryRouter = makeRouter({ |
| 331 | children: <AllTheProviders>{ui}</AllTheProviders>, |
| 332 | history, |
| 333 | config, |
| 334 | outletContext, |
| 335 | }); |
| 336 | |
| 337 | const renderResult = rtl.render( |
| 338 | <RouterProvider router={memoryRouter} future={{v7_startTransition: true}} />, |
| 339 | options |
| 340 | ); |
| 341 | |
| 342 | const rerender = (newUi: React.ReactElement) => { |
| 343 | const newRouter = makeRouter({ |
| 344 | children: <AllTheProviders>{newUi}</AllTheProviders>, |
| 345 | history, |
| 346 | config, |
| 347 | outletContext, |
| 348 | }); |
| 349 | |
| 350 | renderResult.rerender( |
| 351 | <RouterProvider router={newRouter} future={{v7_startTransition: true}} /> |
| 352 | ); |
| 353 | // Force the router to update children |
| 354 | rtl.act(() => newRouter.revalidate()); |
| 355 | }; |
| 356 | |
| 357 | const testRouter = new TestRouter(memoryRouter); |
| 358 | |
| 359 | return { |
| 360 | ...renderResult, |
| 361 | rerender, |
| 362 | router: testRouter, |
| 363 | } as RenderReturn; |
| 364 | } |
| 365 | |
| 366 | function renderHookWithProviders<Result = unknown, Props = unknown>( |
| 367 | callback: (initialProps: Props) => Result, |