testing-anti-patterns

Enforce testing anti-pattern rules for JavaScript/TypeScript unit and integration tests.

3|Updated Oct 18, 2025
One-click install
npx skills add https://github.com/DYAI2025/Stoppclock-page --skill testing-anti-patterns-dyai2025
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-anti-patterns
Source: https://github.com/DYAI2025/Stoppclock-page/tree/main/stoppclock_speckit/.claude/commands/SKILL (19).md
Command: npx skills add https://github.com/DYAI2025/Stoppclock-page --skill testing-anti-patterns-dyai2025

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill prevents common testing mistakes that lead to unreliable, brittle, or misleading tests. It ensures that tests verify actual code behavior rather than mock interactions, keeping your test suite robust and trustworthy.

Core Features & Use Cases

  • Avoid Mock Behavior Testing: Guides you to test real component behavior, not just mock existence.
  • Prevent Production Pollution: Stops the addition of test-only methods to production code.
  • Smart Mocking: Ensures mocks are used effectively, understanding dependencies rather than over-mocking.
  • Use Case: Refactor an existing test suite to remove flakiness, improve test clarity, and ensure that every test provides meaningful validation of your application's functionality.

Quick Start

The Iron Laws:

1. NEVER test mock behavior

2. NEVER add test-only methods to production classes

3. NEVER mock without understanding dependencies

Example: Testing mock behavior (❌ BAD)

test('renders sidebar', () => {

render(<Page />);

expect(screen.getByTestId('sidebar-mock')).toBeInTheDocument();

});

Frequently Asked Questions about testing-anti-patterns

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

FAQPage Schema
How do I stop testing mock behavior instead of real component logic?

Testing mock behavior verifies the mock exists, not your actual code. Instead, test the real component's output and side effects. For example, assert on rendered DOM or function return values, not on whether a mock was called. This ensures tests catch real bugs.

Why are my tests flaky and how do I fix them?

Flaky tests often result from over-mocking, testing mock interactions, or incomplete mock API structures. Eliminate tests that only verify mock existence, ensure mocks mirror full dependency APIs, and mock only external side effects. This stabilizes your test suite and increases confidence.

Can I add helper methods to production code for testing?

No. Test-only production methods pollute your codebase and hide real behavior from tests. Instead, refactor production code to expose necessary behavior through public APIs, or adjust your test approach to work with existing interfaces. Keep production and test concerns separate.

When should I mock dependencies in JavaScript/TypeScript tests?

Mock external dependencies—APIs, databases, file systems—whose behavior you cannot control in tests. Do not mock internal application logic or components under test. Understand each dependency's API fully before mocking to avoid incomplete stubs that hide bugs in real interactions.

How do I refactor an existing test suite to remove anti-patterns?

Audit tests for mock-behavior assertions and test-only production code. Replace mock assertions with real component behavior checks. Restore full dependency API structures in mocks. Test side effects and outputs, not mock calls. Verify each test validates meaningful application functionality.

What's the difference between unit and integration tests in mocking strategy?

Unit tests isolate a single component and mock its external dependencies. Integration tests verify components work together with minimal mocking. Both enforce the same rule: never test mock behavior. Mock only genuine external boundaries; test actual interactions between your code and those boundaries.

Related Skills