# Assertions that pass for the wrong reason
<!--
ref: @protocol/assertions-that-pass-for-the-wrong-reason
tags: [testing, assertions, mutation-testing, jest, validation, false-confidence]
triggers: [wrote a test for a fix, about to claim a guard is covered, mutation check failed fewer tests than expected, test passes but I am not sure it is testing anything]
trigger_prompt: When an agent has written a test for a fix and is about to report the fix as covered — these are the shapes that pass against the defect they were written to catch.
version: 2
updated_at: 2026-10-15T19:59:34.912Z
-->

A test that passes proves the suite ran. It does not prove the assertion was pointed at
the behaviour. These shapes pass **against the broken code they were written to catch**,
and each one was caught by the same cheap method: break the fix on purpose, re-run, and
read the failing COUNT.

## The method, first

For every guard, clause or rule you added: delete it, re-run the suite, record how many
tests fail, restore it. One at a time — a batch tells you the suite noticed *something*.

Read the count, not the colour. "It failed" is satisfied by one test failing when three
should. A count lower than the number of assertions you wrote for that guard is the
signal; it means some of them pass either way.

## The shapes

**`indexOf` returns -1, and -1 is less than every real index.** An assertion that one
clause appears before another —

```js
expect(sql.indexOf('ORDER BY target_id')).toBeLessThan(sql.indexOf('<other>'));
```

— passes when the first clause is GONE, because the miss is -1. Any
`indexOf`/`findIndex`/`search` result compared with `<`, `<=` or `toBeLessThan` has this
hole. Assert presence separately, or match the whole shape with one regex.

**A test that re-declares the thing it tests.** Copy a SQL fragment, a regex, a format
string or a constant into the spec so the spec is self-contained, and it will pass every
mutation of the shipped original. Export the real one and import it. This is the default
failure of an integration spec written beside the unit spec: the unit spec reads the
code, the integration spec reads its own copy, and only one of them is a test.

**A spy satisfied by a different caller.** `expect(cryptoMock).toHaveBeenCalled()` passes
against the unfixed generator when anything else in the call path uses the same
primitive — an id, a nonce, a cache key. Assert the arguments that distinguish the call:
the requested size, the algorithm, the key. Related: a queued `mockReturnValueOnce` goes
to the FIRST caller, not the intended one, so key the fake off its arguments rather than
off call order.

**`.rejects` against a synchronous throw.** A guard that throws at the top of a handler
that is not declared `async` throws synchronously. `await expect(fn()).rejects.toThrow()`
then passes against a function that does not throw at all. Check whether the function is
async before choosing between `.rejects.toThrow()` and `expect(() => fn()).toThrow()`.

**Validation that reaches only the top level.** A request-validation layer configured to
reject undeclared fields typically applies that only to the outermost object. An array
typed as `Foo[]` with no per-item rule declares the container and checks nothing inside
it, so `[{}]` validates and every nested field is unchecked — including the ones the
schema declares REQUIRED. A declaration is not an enforcement until something proves the
nested rule ran.

**A declared-required field the client has never sent.** Follows from the one above: for
as long as the nested rules are off, a required field can be absent from every real
request, and the column it feeds is null everywhere. Grep for what the client actually
puts on the wire, not for what the schema says.

**A test that exercises a mechanism instead of its wiring.** A spec that constructs the
validation pipe itself and feeds it a DTO proves the DTO and the pipe. It says nothing
about whether any ROUTE binds that DTO — so it passes unchanged while the route next to it
is typed `@Body() body: { data: any }`, which erases to `Object` and makes the framework
skip the pipe entirely. (So does `import type` of a real DTO class: the metatype the
framework reads at runtime is erased with the import.) Found 2026-10-15 on a route whose
body had been unvalidated for the lifetime of three separate comments claiming it was
covered, including the spec's own heading. Assert the WIRING: read the binding back from
the framework's own metadata —
`Reflect.getMetadata('design:paramtypes', Controller.prototype, method)` — and keep a
deliberately-unwired route in the same block as the control. The general form: when a
mechanism is configured in one place and consumed in another, a test of the mechanism and
a test of the consumption are different tests, and only the second one can fail when the
wiring is removed.

## Corollary — turning nested validation on is a client change

The moment per-item rules start running, every field the client sends that the schema
does not declare becomes a rejection. Narrow the client in the same change and pin the
narrowing with a test over the built request, or the first upload after the fix is a 400.

---

*A guard asserted only by the test you wrote for it is covered by exactly as much as that
test actually checks. The mutation count is the cheapest thing that tells you which.*

---

*Related: `@content/youtube/nate-herk/i-deleted-all-my-claude-skills-and-claude-got-smarter` · `@content/youtube/cole-medin/11-more-tiny-coding-agent-fixes-with-a-stupid-amount-of-payoff-learn-these-now` · `@content/youtube/starter-story/my-apps-make-36k-month-watch-me-build-one-in-17-minutes` · `@content/youtube/nate-herk/i-made-codex-and-claude-code-build-the-same-app-one-clearly-won` · `@content/youtube/cole-medin/11-tiny-coding-agent-fixes-with-a-stupid-amount-of-payoff`*

---

*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*

*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*