Skip to content

Test hardening: keep noUnusedLocals on test tsconfig + field-scoped negative assertions as convention #224

Description

@strausmann

Follow-up from the test-hardening review of PRs #210#215. Several tests passed while proving nothing; the fixes taught two mechanical rules worth enforcing repo-wide.

1. Keep noUnusedLocals / noUnusedParameters on the test tsconfig

tsconfig.tests.json already sets these (added in #213). The reason to keep it explicit: a dead assertion — a value parsed from output into a local that is then never asserted on — becomes a compile error instead of a silently green test. Do not relax these flags for test files.

  • Confirm noUnusedLocals + noUnusedParameters are set on the test tsconfig and cannot be overridden per-file
  • Add a one-line comment there stating why (catches dead assertions), so it is not "cleaned up" later

2. Field-scoped negative assertions (convention)

A negative assertion over a whole serialized blob is a coincidence waiting to happen. expect(raw).not.toContain('42') also matches a timestamp, an id, or an unrelated field — it can pass for the wrong reason and fail flakily. Real case in #215: not.toContain('42') collided with a timestamp.

Rule: a negative assertion must name the field it denies. Parse the output and assert on the specific key (obj.route, obj.err.type), not on the raw string.

  • Sweep the test suite for not.toContain( / not.toMatch( over raw serialized output; scope each to a field
  • Note the convention in the test README / CONTRIBUTING so new tests follow it

3. Mutation check as the bar for "does this test catch the bug"

Standard from the same review: run every new regression test once against the un-fixed code. If it stays green there, it proves nothing (a fallback path, a duplicate-key dedupe, or an env-driven later failure can keep it green for the wrong reason — all three happened across #214/#215). Make this an explicit step in the test-writing checklist.

  • Add "counter-check against the un-fixed code" to the contributing/test guidance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions