testing-anti-patterns

Detect test and mock anti-patterns in TypeScript/JavaScript projects.

4|Updated Dec 7, 2020
One-click install
npx skills add https://github.com/charly3pins/dotfiles --skill testing-anti-patterns-charly3pins
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-anti-patterns
Source: https://github.com/charly3pins/dotfiles/tree/main/.config/opencode/skills/testing-anti-patterns
Command: npx skills add https://github.com/charly3pins/dotfiles --skill testing-anti-patterns-charly3pins

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Common testing mistakes like testing mock behavior, polluting production code with test-only methods, or incomplete mocks lead to fragile tests and false confidence in code quality.

Core Features & Use Cases

  • Iron Law Enforcement: Prevents testing mock behavior, adding test-only methods to production, and mocking without understanding dependencies.
  • Gate Functions: Provides specific checks before asserting on mocks, adding methods, or creating mock responses.
  • TDD Integration: Explains how following Test-Driven Development naturally prevents these anti-patterns.
  • Use Case: When writing new tests or refactoring existing ones, use this skill to identify and avoid anti-patterns such as asserting on mock elements or creating incomplete mock responses, ensuring your tests verify real code behavior.

Quick Start

I am writing a new test. Help me identify and avoid common testing anti-patterns, especially regarding mocks.

Frequently Asked Questions about testing-anti-patterns

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

FAQPage Schema
How do I avoid testing mock behavior instead of real code?

Testing mock behavior creates false confidence in code quality. Instead, verify that your production code correctly calls mocks and handles their responses—test the integration between your code and its dependencies, not the mock itself. This ensures tests validate actual behavior.

Why shouldn't I add test-only methods to production code?

Test-only methods pollute production code and create a gap between what you test and what runs in production. Keep production code free of testing concerns by refactoring dependencies or using proper mocking instead, so tests validate real-world behavior.

What's the right way to mock dependencies in unit tests?

Mock dependencies only after understanding what they do and why your code needs them. Create complete, realistic mock responses that reflect actual behavior. This prevents incomplete mocks from masking bugs and ensures your tests catch real integration issues.

How does Test-Driven Development prevent testing anti-patterns?

TDD naturally prevents anti-patterns by forcing you to write tests before code. You design dependencies upfront, mock intentionally, and avoid polluting production with test logic. Tests stay focused on behavior, not implementation details.

Can I use this to refactor existing tests in React components?

Yes. This applies to unit and integration tests across TypeScript/JavaScript projects, including React components. Identify assertions on mock elements, incomplete mock responses, or test-only helper methods, then refactor to test actual component behavior and real dependencies.

What testing frameworks does this work with?

Anti-pattern detection applies to any testing framework in TypeScript/JavaScript projects. The principles—never test mock behavior, never add test-only production methods, never mock without understanding dependencies—are framework-agnostic and work with Jest, Vitest, Mocha, or other tools.