Snapshot Testing
Understand what snapshot tests capture, their legitimate uses, and why they're easy to misuse as a substitute for real assertions.
A snapshot test renders a component (or serializes some other value) and saves the resulting output to a file; on subsequent test runs, the current output is compared against that saved snapshot, and the test fails if they differ, prompting the developer to either fix an unintended regression or explicitly update the snapshot if the change was intentional. Jest's built-in snapshot testing (toMatchSnapshot()) is the most common implementation in a React testing setup.
Snapshot testing is like keeping a photograph of a room's exact layout and comparing new photos against it to spot if anything's moved — genuinely useful for noticing an unexpected change, but if you get in the habit of just re-taking and accepting a new 'reference' photo every time something looks different without actually checking why, the photo stops meaningfully protecting against anything.