principle-test-behavior-not-implementation

Rewrites or deletes tests that assert implementation details instead of observable behavior.

4|1|Updated Dec 16, 2023
One-click install
npx skills add https://github.com/Shtian/AuthentiClash --skill principle-test-behavior-not-implementation-shtian
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: principle-test-behavior-not-implementation
Source: https://github.com/Shtian/AuthentiClash/tree/main/.claude/skills/principle-test-behavior-not-implementation
Command: npx skills add https://github.com/Shtian/AuthentiClash --skill principle-test-behavior-not-implementation-shtian

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Test suites accumulate tests that cannot fail for a defect: assertions on mock calls, restated constants, or self-referential comparisons. These tests cost CI time and review attention while catching nothing, and constant pins actively block legitimate edits. ## Core Features & Use Cases - Behavior-First Test Review: Applies a single check to any test: would it still pass if every imported function returned undefined? If yes, the test observes no behavior. - Five Anti-Pattern Detection: Identifies weak assertions (toBeDefined, toBeTruthy), mock-only assertions (toHaveBeenCalled), self-referential expectations, constant pins, and fixture-asserts-fixture patterns. - Concrete Rewrite Guidance: Prescribes calling the subject with one concrete input and asserting the literal output, such as expect(slugify("Hello, World!")).toBe("hello-world"). - Use Case: While reviewing a pull request, apply this Skill to flag a test that only checks toHaveBeenCalled on a mock and rewrite it to assert the payload the mock received. ## Quick Start Review the tests in this file and rewrite or delete any that would still pass if every imported function returned undefined.

Frequently Asked Questions about principle-test-behavior-not-implementation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test behavior instead of implementation?▼

Call the code the way its users do and assert the result they observe against a literal expected value. Avoid asserting which internal calls were made or restating constants the code contains.

What makes a unit test unable to catch defects?▼

A test catches nothing if it would still pass when every imported function returns undefined. Common shapes include weak assertions like toBeDefined, mock-only checks like toHaveBeenCalled, and self-referential expectations.

Should I use toHaveBeenCalled in Jest or Vitest tests?▼

Asserting only that a mock was called verifies no behavior. Instead, assert the payload the mock received or the state after the call, so the test fails when the actual behavior breaks.

When is it acceptable to keep a constant assertion test?▼

Restating a constant like expect(LIMITS.maxTools).toBe(8) only pins the value and blocks edits. Test the mechanism that reads the constant with one concrete input instead of duplicating the value.

Which tests should be kept under this principle?▼

Keep tests of relations across table rows, such as a key present in two tables or an existing parent record, and compile-time checks in *.test-d.ts files. Everything else must assert observable behavior.