Reviewer · Testing
Assertions must catch regressions
A test only has value if it fails when the behavior it claims to guard actually breaks. Before adding or approving an assertion, ask: "what real bug would this catch?" Several recurring anti-patterns slip past review because the test passes today for the wrong reason:
A test only has value if it fails when the behavior it claims to guard actually breaks. Before adding or approving an assertion, ask: “what real bug would this catch?” Several recurring anti-patterns slip past review because the test passes today for the wrong reason:
- Self-referential/tautological checks: comparing a constant or a hand-copied table to itself (e.g.
expect(STATUS_KIND).toEqual({...copy of the source map...}), or assertingmaxAttempts === 1against the literal the code sets). These only fail if someone edits the value on purpose — drop them, or replace with a test that exercises the behavior the value drives. - Weak matchers that hide the real failure mode:
toBeDefined(),toHaveProperty, or asserting only that an error message contains a key fragment (e.g./catalog\.maxManifestEntries/) let an unrelated or wrong error pass. Pin the exact expected value/message so a different failure is caught. - Mocking/injecting at the wrong boundary: stubbing a dependency that the real code path never calls (e.g. rejecting from a helper that isn’t actually on the call chain, or asserting on a mocked error class instead of exercising the real validation) gives false confidence that integration is covered. Make the mock sit exactly where the production code calls out, and prefer one true integration/API test for the path that matters most.
- Duplicated or overlapping tests: two tests with the same title/setup (e.g. “accepts an https URL” defined twice), or a unit test re-asserting what an API/integration test already covers more strongly, add maintenance cost without new coverage — consolidate with
it.eachor delete the redundant one. - Pinning incidental implementation detail instead of the contract that matters: asserting an exact upstream status code or exact literal order of an array when only the semantic outcome (e.g. “unsupported”, “same steps regardless of order”) is the real contract — assert the behavior, not the implementation accident (
.sort()ids, check for a 4xx + message substring instead of a specific code). - Relaxing an assertion while removing part of what it checked: when simplifying a strict
toEqualinto a narrower check, explicitly verify you haven’t dropped a property that mattered (e.g. a group’s label, or “only one strategy passes”).
When adding a test, write it so you can state concretely what change in the code would make it fail, and make sure that change is the one you actually care about.