testing-anti-patterns

Enforce rules against testing anti-patterns in TypeScript/JavaScript test suites.

270k|24.1k|Updated Oct 9, 2025
One-click install
npx skills add https://github.com/obra/superpowers --skill testing-anti-patterns-obra
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-anti-patterns
Source: https://github.com/obra/superpowers/tree/main/skills/testing-anti-patterns
Command: npx skills add https://github.com/obra/superpowers --skill testing-anti-patterns-obra

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill prevents common mistakes that lead to unreliable, brittle, or misleading tests. It guides you away from testing mock behavior, polluting production code with test-only methods, and creating incomplete mocks, ensuring your tests provide genuine confidence.

Core Features & Use Cases

  • Mock Behavior Prevention: Guides you to test actual component behavior, not just the existence or function of mocks, ensuring your tests are meaningful.
  • Clean Production Code: Ensures test-only methods don't creep into your production codebase, maintaining strict separation of concerns and preventing accidental production calls.
  • Effective Mocking: Teaches how to mock dependencies minimally and completely, avoiding silent failures due to partial mocks that hide structural assumptions.
  • Use Case: When you're tempted to assert on a mock's internal state (e.g., expect(screen.getByTestId('sidebar-mock'))), this skill reminds you to instead test the real component's behavior, ensuring your tests provide genuine confidence in your application.

Quick Start

Example: Avoiding testing mock behavior

❌ BAD: Testing that the mock exists

test('renders sidebar', () => { render(<Page />); expect(screen.getByTestId('sidebar-mock')).toBeInTheDocument(); });

✅ GOOD: Test real component or don't mock it

test('renders sidebar', () => { render(<Page />); # Don't mock sidebar if not necessary for isolation expect(screen.getByRole('navigation')).toBeInTheDocument(); # Test real element });

Gate Function:

BEFORE asserting on any mock element:

Ask: "Am I testing real component behavior or just mock existence?"

IF testing mock existence:

STOP - Delete the assertion or unmock the component

Test real behavior instead

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 component behavior?

Testing mock behavior means asserting on mock existence rather than actual functionality. Instead, test real component output—verify the element renders, not that the mock exists. Remove unnecessary mocks or assert on genuine behavior like DOM queries or user interactions.

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

Test-only methods pollute production code and blur the line between testable and deployable logic. Keep production code clean by testing through public APIs only. If you need special test hooks, use dependency injection or test doubles at the boundary instead.

What happens when I mock without understanding dependencies?

Incomplete or incorrect mocks hide structural assumptions and create silent failures. Before mocking, understand what the dependency does and what behavior your code relies on. Mock completely—ensure the mock covers all interactions your code might make.

How do I know if my test suite has anti-patterns?

Common signs: assertions on mock elements, test-only production methods, partial mocks that don't fully simulate dependencies, or tests passing when production code would fail. Audit tests by checking whether you're validating real behavior or just mock plumbing.

Can I use this with TypeScript and JavaScript projects?

Yes, this skill applies directly to TypeScript and JavaScript testing. It guides test design principles—mock behavior prevention, clean code separation, and complete mocking—that work across any JavaScript testing framework.

What's the difference between testing real behavior and testing mocks?

Testing real behavior verifies that your component or function produces correct output under real conditions. Testing mocks only confirms the mock exists or was called, not that your code actually works. Real behavior tests give genuine confidence; mock-only tests are brittle and misleading.