testing-anti-patterns

Prevent tests from asserting mock behavior and polluting production code.

Updated Feb 17, 2026
One-click install
npx skills add https://github.com/tim-hub/role-based-skills --skill testing-anti-patterns-tim-hub
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-anti-patterns
Source: https://github.com/tim-hub/role-based-skills/tree/main/testing-anti-patterns
Command: npx skills add https://github.com/tim-hub/role-based-skills --skill testing-anti-patterns-tim-hub

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Prevents tests from validating mock behavior, adding test-only methods to production code, and breaking tests by over-mocking or using incomplete mocks so that tests reflect real system behavior and catch real regressions.

Core Features & Use Cases

  • Mock behavior prevention: Guidance to avoid asserting on mock internals and instead verify real component behavior.
  • Test-only code avoidance: Patterns to move cleanup and test helpers into test utilities rather than production classes.
  • Responsible mocking: Gate checks to understand dependency side effects, create complete mocks, and mock at the correct level.
  • Use Case: When a developer is writing or refactoring unit or integration tests in a JavaScript/TypeScript codebase and needs to ensure tests remain reliable and maintainable.

Quick Start

Analyze my failing or fragile test and rewrite it to assert real behavior, unmock the component, or move test-only cleanup into test utilities as appropriate.

Frequently Asked Questions about testing-anti-patterns

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

FAQPage Schema
Why does my unit test pass but the integration fails when using mocks?

Unit tests often pass while integration fails because they validate mock internals rather than real behavior. Avoid asserting mock behavior and ensure mocks preserve real dependency side effects to catch actual regressions.

How do I remove test-only methods from my production code?

To remove test-only methods from production code, migrate test-only cleanup logic and helpers into dedicated test utilities. This prevents polluting production classes and maintains clean separation between production and test logic.

What are the gate checks for responsible mocking in JavaScript and TypeScript?

Responsible mocking requires gate checks to understand dependency side effects, create complete mock structures, and mock at the correct level. This prevents over-mocking and incomplete mocks from breaking tests in JavaScript and TypeScript codebases.

How do I fix fragile tests that rely on over-mocking?

Fix fragile tests by rewriting them to assert real behavior, unmocking the component, or moving test-only cleanup into test utilities. This ensures tests reflect real system behavior and remain reliable over time.

Does this testing approach work for both unit and integration tests?

Yes, this approach applies when writing or modifying both unit and integration tests. It enforces TDD practices and responsible mocking across JavaScript and TypeScript codebases to prevent validating mock behavior and polluting production code.