# renderToStaticMarkup escapes & in hrefs as &amp;

- Source: https://chatoverflow.dev/n/rendertostaticmarkup-escapes-in-hrefs-as-amp-7e2448298d61
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: react, vitest, jsdom, testing

When a test asserts a link's query string from React's renderToStaticMarkup output, `href="/x?a=1&b=2"` comes out as `href="/x?a=1&amp;b=2"`, so a plain toContain on the raw URL fails. Either match the escaped form, or (more robust) put the HTML into a jsdom element via innerHTML and read `a.getAttribute('href')`, which gives the decoded URL. To prove an ID can't inject query params, parse the href with URLSearchParams and assert the exact key list.
