essential-test-design
Write tests that verify observable behavior (contract), not implementation details. Auto-invoked when writing or reviewing tests.
Install
mkdir -p .claude/skills/essential-test-design && curl -L -o skill.zip "https://mcp.directory/api/skills/download/2727" && unzip -o skill.zip -d .claude/skills/essential-test-design && rm skill.zipInstalls to .claude/skills/essential-test-design
About this skill
Problem
Tests that are tightly coupled to implementation details cause two failures:
- False positives — Tests pass even when behavior is broken (e.g., delay shortened but test still passes because it only checks
setTimeoutwas called) - False negatives — Tests fail even when behavior is correct (e.g., implementation switches from
setTimeoutto adelay()utility, spy breaks)
Both undermine the purpose of testing: detecting regressions in behavior.
Principle: Test the Contract, Not the Mechanism
A test is "essential" when it:
- Fails if the behavior degrades (catches real bugs)
- Passes if the behavior is preserved (survives refactoring)
- Does not depend on how the behavior is implemented (implementation-agnostic)
Ask: "What does the caller of this function experience?" — test that.
Anti-Patterns and Corrections
Anti-Pattern 1: Implementation Spy
// BAD: Tests implementation, not behavior
// Breaks if implementation changes from setTimeout to any other delay mechanism
const spy = vi.spyOn(global, 'setTimeout');
await exponentialBackoff(1);
expect(spy).toHaveBeenCalledWith(expect.any(Function), 1000);
Anti-Pattern 2: Arrange That Serves the Assert
// BAD: The "arrange" is set up only to make the "assert" trivially pass
// This is a self-fulfilling prophecy, not a meaningful test
vi.advanceTimersByTime(1000);
await promise;
// No assertion — "it didn't throw" is not a valuable test
Correct: Behavior Boundary Test
// GOOD: Tests the observable contract
// "Does not resolve before the expected delay, resolves at the expected delay"
let resolved = false;
mailService.exponentialBackoff(1).then(() => { resolved = true });
await vi.advanceTimersByTimeAsync(999);
expect(resolved).toBe(false); // Catches: delay too short
await vi.advanceTimersByTimeAsync(1);
expect(resolved).toBe(true); // Catches: delay too long or hangs
Decision Framework
When writing a test, ask these questions in order:
- What is the contract? — What does the caller expect to experience?
- e.g., "Wait for N ms before resolving"
- What breakage should this test catch? — Define the regression scenario
- e.g., "Someone changes the delay from 1000ms to 500ms"
- Would this test still pass if I refactored the internals? — If no, you're testing implementation
- e.g., Switching from
setTimeouttoBun.sleep()shouldn't break the test
- e.g., Switching from
- Would this test fail if the behavior degraded? — If no, the test has no value
- e.g., If delay is halved,
expect(resolved).toBe(false)at 999ms would catch it
- e.g., If delay is halved,
Common Scenarios
Async Delay / Throttle / Debounce
Use fake timers + boundary assertions (as shown above).
Data Transformation
Assert on output shape/values, not on which internal helper was called.
// BAD
const spy = vi.spyOn(utils, 'formatDate');
transform(input);
expect(spy).toHaveBeenCalled();
// GOOD
const result = transform(input);
expect(result.date).toBe('2026-01-01');
Side Effects (API calls, DB writes)
Mocking the boundary (API/DB) is acceptable — that IS the observable behavior.
// OK: The contract IS "sends an email via mailer"
expect(mockMailer.sendMail).toHaveBeenCalledWith(
expect.objectContaining({ to: 'user@example.com' })
);
Retry Logic
Test the number of attempts and the final outcome, not the internal flow.
// GOOD: Contract = "retries N times, then fails with specific error"
mockMailer.sendMail.mockRejectedValue(new Error('fail'));
await expect(sendWithRetry(config, 3)).rejects.toThrow('failed after 3 attempts');
expect(mockMailer.sendMail).toHaveBeenCalledTimes(3);
When to Apply
- Writing new test cases for any function or method
- Reviewing existing tests for flakiness or brittleness
- Refactoring tests after fixing flaky CI failures
- Code review of test pull requests
More by growilabs
View all skills by growilabs →You might also like
flutter-development
aj-geddes
Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.
drawio-diagrams-enhanced
jgtolentino
Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.
ui-ux-pro-max
nextlevelbuilder
"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."
godot
bfollington
This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.
nano-banana-pro
garg-aayush
Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.
fastapi-templates
wshobson
Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.
Related MCP Servers
Browse all serversLearn how to use Python to read a file and manipulate local files safely through the Filesystem API.
Automate Excel file tasks without Microsoft Excel using openpyxl and xlsxwriter for formatting, formulas, charts, and ad
DeepWiki converts deepwiki.com pages into clean Markdown, with fast, secure extraction—perfect as a PDF text, page, or i
Unlock powerful Excel automation: read/write Excel files, create sheets, and automate workflows with seamless integratio
Get secure read and write access to your Airtable databases. Learn about Airtable API features, pricing, and cost-effect
Test apps seamlessly with BrowserStack's testing infrastructure. Verify mobile app functionality, cross-browser issues,
Stay ahead of the MCP ecosystem
Get weekly updates on new skills and servers.