{"data":{"slug":"github-thedaviddias-front-end-checklist-skills-mock-best-practices-31e8166fb6c8","title":"Follow Mocking Best Practices for Testing","summary":"Ensure tests isolate units under test while remaining realistic by avoiding over-mocking and properly cleaning up mocks using tools like Jest and MSW.","url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-mock-best-practices-31e8166fb6c8","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-thedaviddias-front-end-checklist-skills-mock-best-practices-31e8166fb6c8","markdown_url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-mock-best-practices-31e8166fb6c8.md","download_url":"https:\/\/skillshunter.net\/skills\/github-thedaviddias-front-end-checklist-skills-mock-best-practices-31e8166fb6c8\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Use jest.restoreAllMocks() in afterEach to clean up mocks and consider MSW for realistic API mocking without coupling to implementation.","instructions":"---\nname: mock-best-practices\ndescription: \"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.\"\nmetadata:\n  category: testing\n  priority: medium\n  difficulty: intermediate\n  estimatedTime: \"20\"\n  source: frontendchecklist.io\n  url: https:\/\/frontendchecklist.io\/rules\/testing\/mock-best-practices\n---\n\n# Follow mocking best practices\n\nProper mocking isolates units under test while keeping tests realistic\u2014over-mocking creates false confidence when tests pass but production breaks.\n\n## Quick Reference\n\n- Mock external dependencies (APIs, databases, file system), not business logic\n- Always clean up mocks with jest.restoreAllMocks() in afterEach\n- Use MSW for realistic API mocking without coupling to implementation\n- Test behavior and outputs, not internal implementation details\n\n## Check\n\nReview this test file for mocking patterns, checking for over-mocking, missing mock cleanup, and proper mock implementation.\n\n## Fix\n\nImprove mocking strategy by removing unnecessary mocks, adding proper cleanup, and mocking at the right level of abstraction.\n\n## Explain\n\nExplain mocking best practices including when to mock, what to mock, and common mocking pitfalls.\n\n## Code Review\n\nReview 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.\n\n---\n\nFor full implementation details, code examples, and framework-specific guidance,\nsee `references\/rule.md`.\n\nRule page: https:\/\/frontendchecklist.io\/rules\/testing\/mock-best-practices\n","use_cases":["Reviewing test files for over-mocking and missing mock cleanup","Improving test strategy by refining mocking patterns","Ensuring automated checks verify mocking best practices in CI workflows"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/thedaviddias\/Front-End-Checklist\/blob\/e8d14d049010e2ce25afcd5e8609dfcbbe63e47e\/skills\/mock-best-practices\/SKILL.md","source_commit":"e8d14d049010e2ce25afcd5e8609dfcbbe63e47e","license":null,"version":null,"listing_approved_at":"2026-11-23","created_at":"2026-11-22T17:06:09.000000Z","updated_at":"2026-11-23T04:55:39.000000Z","seo_title":"Follow Mocking Best Practices for Testing","seo_description":"Improve test reliability by following mocking best practices, including proper mock cleanup and avoiding over-mocking.","seo_keywords":["mocking best practices","test isolation","mock cleanup","over-mocking","test strategy"]}}