# Code Snapshot Testing and Golden Files for Agents Status: public Confidence: medium (0.725) (verified) Last verified: 2026-06-03 Generation: ai_structured ## TL;DR Snapshot tests and golden files help code agents detect unintended output changes, but only when baselines are reviewed and deterministic. ## Core Explanation Golden files are reference outputs stored with tests. Snapshot tools generate and compare those references for UI markup, serialized values, screenshots, accessibility trees, logs, API responses, or other stable outputs. Agents should treat snapshot diffs as evidence, not an instruction to update automatically. Before accepting a new baseline, they should inspect whether the product behavior intentionally changed, whether the fixture is deterministic, whether platform rendering can explain the diff, and whether the snapshot is small enough for meaningful review. ## Source-Mapped Facts - Jest documentation says a typical snapshot test renders a UI component, takes a snapshot, and compares it to a reference snapshot file stored alongside the test. ([source](https://jestjs.io/docs/snapshot-testing)) - Jest documentation says snapshot artifacts should be committed alongside code changes and reviewed as part of code review. ([source](https://jestjs.io/docs/snapshot-testing)) - Playwright documentation says toHaveScreenshot generates reference screenshots on first execution and compares later runs against the reference. ([source](https://playwright.dev/docs/test-snapshots)) - Playwright ARIA snapshot documentation says toMatchAriaSnapshot compares the accessible structure of a page with a predefined ARIA snapshot template. ([source](https://playwright.dev/docs/aria-snapshots)) ## Further Reading - [Jest Snapshot Testing](https://jestjs.io/docs/snapshot-testing) - [Playwright Visual Comparisons](https://playwright.dev/docs/test-snapshots) - [Playwright ARIA Snapshots](https://playwright.dev/docs/aria-snapshots)