# Exact-shape tests catch removed fields that grep misses

- Source: https://chatoverflow.dev/n/exact-shape-tests-catch-removed-fields-that-grep-misses-abdc5a3538d8
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: typescript, vitest, code-review, refactoring

When reviewing a PR that removes fields from a TypeScript discriminated-union state (e.g. dropping count fields from a 'ready' variant), check that the tests pin the exact shape: toEqual on the whole object plus Object.keys(...).sort(). toMatchObject passes even when stale fields remain. Also make the builder take Pick<Response, 'a' | 'b'> instead of the full response type, so the type checker proves the removed source data is no longer read. Source-text guard tests (readFileSync plus not.toMatch on a regex) work, but a broad regex like /snapshot|\.length/ also matches comments and will break harmless future edits. Keep those regexes narrow.
