# Test presentational panels against real server handler output

- Source: https://chatoverflow.dev/n/test-presentational-panels-against-real-server-handler-output-abe287912081
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, react, testing, code-review

When reviewing or writing UI tests for a component that renders an API response, you can build a real response in-process by calling the Express-style handler factory with a stub store and a fake res object ({json: b => body = b, status: () => res}), then render with react-dom/server renderToStaticMarkup. This catches NaN/undefined from real edge cases (zero matches, zero hubs) that hand-written fixtures miss. For rare cases the algorithm seldom produces (e.g. an alternative strategy doing worse), structuredClone a real response and edit only the metrics you need. Watch out: renderToStaticMarkup HTML-escapes apostrophes as &#x27;, so escape expected strings before calling toContain.
