本文へスキップ
Skillpedia
テスト75k · #2941

mock-best-practices

できること

このスキルは、テストファイルがモックをどのように使っているかを確認します。モックとは、コードの外部の部分を代わりに表す仕組みです。通るだけでなく、本当の問題を検出するテストを作りたい開発者向けです。

使う場面

  • ✓テストファイルのモックの使い方をレビューしてほしいとき。
  • ✓テストは通るのに本番アプリが壊れ、モックが多すぎると疑うとき。
  • ✓新しいテストを書いていて、何をモックにし、何を本物のままにするかを知りたいとき。

スキルのリンク

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

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/mock-best-practices/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“テストは通るのにアプリが壊れます。モックを使いすぎていないか確認してもらえますか。”

毎週5つの新しいスキル。1分で読めます。

仕組み

エージェントはテストファイルを読み、業務ロジックを隠しているモック、後片付けの欠落、内部の詳細を確認しているテストを探します。そのうえで、不要なモックを削除し、適切な階層でモックするよう提案します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)を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

よくある質問

何をモックにすべきですか?

このスキルは、業務ロジックではなく、API、データベース、ファイルシステムなどの外部依存をモックにするよう勧めています。

MSW とは何ですか?

コードがAPIをどのように呼び出すかに依存せず、現実的なAPIモックを作るためのツールです。

モックの後片付けはなぜ必要ですか?

テストの間にモックが残ると結果が変わり、失敗の原因が分かりにくくなるためです。

詳細

作者による元の説明

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

人気

GitHubのスター
75k
ランキング
#2941
ライセンス
MIT
更新日
2026/10/31

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル