Skip to content
Skillpedia
Testing75k · #2941

mock-best-practices

What it does

This skill reviews how a test file uses mocks, which are stand-ins for outside parts of the code. It is for developers who want tests that catch real problems rather than only passing.

When to use it

  • ✓When you ask the agent to review how a test file uses mocks.
  • ✓When tests pass but the real app breaks, and you suspect too much is being mocked.
  • ✓When you are writing new tests and want guidance on what to mock and what to leave real.

Skill link

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/mock-best-practices/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/mock-best-practices/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“My tests pass but the app still breaks. Can you check whether I am mocking too much?”

5 new skills a week. 1 minute to read.

How it works

The agent reads the test file and looks for mocks that hide business logic, missing cleanup, and tests that check internal details. It then suggests removing unnecessary mocks and mocking at the right level.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Follow mocking best practices

Proper mocking isolates units under test while keeping tests realistic—over-mocking creates false confidence when tests pass but production breaks.

Quick Reference

  • Mock external dependencies (APIs, databases, file system), not business logic
  • Always clean up mocks with jest.restoreAllMocks() in afterEach
  • Use MSW for realistic API mocking without coupling to implementation
  • Test behavior and outputs, not internal implementation details

Check

Review this test file for mocking patterns, checking for over-mocking, missing mock cleanup, and proper mock implementation.

Fix

Improve mocking strategy by removing unnecessary mocks, adding proper cleanup, and mocking at the right level of abstraction.

Explain

Explain mocking best practices including when to mock, what to mock, and common mocking pitfalls.

Code Review

Review tests, CI workflows, and enforcement points related to Follow mocking best practices. Flag exact gaps where the rule is not automatically verified or where failures do not block regressions.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/testing/mock-best-practices

FAQ

What should be mocked?

The skill says to mock external dependencies such as APIs, databases, and the file system, not business logic.

What is MSW?

It is a tool for realistic API mocking that does not depend on how your code calls the API.

Why clean up mocks?

Mocks left in place between tests can change results and make failures hard to understand.

Details

Original description by the author

Use when reviewing CI coverage, automated checks, or test strategy related to Follow mocking best practices. Focus on whether the rule is continuously verified, not just documented.

repo: thedaviddias/Front-End-Checklist

Popularity

GitHub stars
75k
Ranking position
#2941
License
MIT
Updated
10/31/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills