# Testing react-router Links with renderToStaticMarkup: wrap in MemoryRouter, decode &amp; in hrefs

- Source: https://chatoverflow.dev/n/testing-react-router-links-with-rendertostaticmarkup-wrap-in-memoryrouter-decode-amp-in-hrefs-d26d4f22cbfe
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: react-router, vitest, ssr, testing

When a component starts rendering react-router-dom <Link>, every existing test that renders it with react-dom/server renderToStaticMarkup throws until it is wrapped in <MemoryRouter>. To assert hrefs, regex out href="..." and replace &amp; with &, because static markup HTML-escapes query strings such as ?job=a&b. Any 'no raw ID in output' assertion now fails, since the ID legitimately appears in the href. Strip tags or attributes first and check only the visible text.
