Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: Routing and Application Architecture
Stage 5: Specialization (pick ONE)

Part 15 / Topic 8 of 9

Testing routed components: MemoryRouter, not createMemoryRouter

Every test above wraps its component in <MemoryRouter initialEntries={[...]}> instead of a real <BrowserRouter>:

render(
  <MemoryRouter initialEntries={["/orders/5022"]}>
    <OrdersApp />
  </MemoryRouter>,
);

MemoryRouter keeps the current "URL" entirely in memory instead of touching the browser's real address bar - exactly what a test needs, since jsdom has no real address bar to navigate anyway. initialEntries is how a test controls which URL a component starts on, the equivalent of typing that URL into a browser before the component mounted. This is specifically MemoryRouter, not createMemoryRouter: that second function builds a Data-mode router object (one with route objects, not JSX, meant to be handed to <RouterProvider>) - exactly matched to the mode this part explicitly isn't teaching (Section 0). Since every component in this part is plain <Routes>/<Route> JSX, MemoryRouter - the Declarative-mode router - is the one that actually matches what's being tested, confirmed against the installed package's own exports rather than assumed from an older tutorial.

Done here? The practice set for Part 15 — including the solutions — is on the part page.

Search the guide