agentleFS
PradnyeshpPradnyeshp/Claude-Skills/.claude/skills/mock/SKILL.md

mock

Skill2 starsChanged 4 months agoMITView on GitHub

Generate test doubles — mocks, stubs, fakes, spies — for a unit's external dependencies, matching the project's testing and mocking approach, so a unit test can run in isolation. Use when the user says "mock this dependency", "create a stub for", "mock the API call", "fake the database", "add a test double", or "how do I mock X in tests".

7 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. 0 are common, 4 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 7 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Create a test double for the dependency in $ARGUMENTS so the unit under test can be tested in isolation.

    line 17
  2. Distinctive:

    Prefer the simplest that fits.

    line 26
  3. Very specific:

    Reset between tests: Ensure mocks are cleared/restored in teardown so state doesn't leak across tests.

    line 28
  4. Distinctive:

    Keep doubles faithful to the real interface and reset them between tests so suites stay isolated and order-independent.

    line 34
  5. Distinctive:

    Prefer a fake or stub over a strict call-asserting mock unless the interaction itself is the behavior being verified — brittle …

    line 35
  6. Distinctive:

    After writing, show where the double is wired, what it returns/asserts, and the command to run the affected tests.

    line 36

“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Test & mocking setup

!find . -type d \( -name node_modules -o -name .git -o -name dist -o -name build \) -prune -o -type f \( -name '*.test.*' -o -name '*.spec.*' -o -name 'test_*.py' -o -name 'conftest.py' -o -name '*_test.go' \) -print 2>/dev/null | head -15

!grep -rilE "jest\\.mock|vi\\.mock|sinon|unittest\\.mock|@patch|monkeypatch|nock|msw|gomock|mockito|testify/mock" --include='*.*' . 2>/dev/null | grep -vE 'node_modules|\.git|dist|build' | head -10

Instructions

Create a test double for the dependency in $ARGUMENTS so the unit under test can be tested in isolation. Match the project's existing test framework and mocking style — don't introduce a new mocking library.

Method

  1. Learn the mocking convention. From the signals above, identify the framework and how the project already mocks (jest.mock/vi.mock, sinon, unittest.mock/@patch/pytest monkeypatch, nock/MSW for HTTP, gomock/testify, Mockito). Read a neighboring test to match the setup/teardown and assertion style. If nothing exists, propose the idiomatic approach and confirm.
  2. Pick the right kind of double for the need:
    • Stub — returns canned values so the unit can proceed (a repo that returns a fixed record).
    • Mock/spy — asserts the dependency was called correctly (args, count) when the interaction is the behavior under test.
    • Fake — a lightweight working implementation (in-memory repo, MSW handler) when many tests need realistic behavior. Prefer the simplest that fits; don't assert on calls that aren't the point of the test.
  3. Mock at the seam, against the real interface. Replace the dependency at its boundary (the injected collaborator, the module import, the HTTP endpoint), and make the double honor the real signature/return type so the test fails if the contract drifts. Cover the cases the test needs: success, empty, and error/throw.
  4. Reset between tests. Ensure mocks are cleared/restored in teardown so state doesn't leak across tests. Use the framework's reset (afterEach(jest.clearAllMocks), restore(), autouse fixtures).

Rules

  1. Match the project's framework and mocking library exactly; don't add a new one unprompted.
  2. Mock only external/slow/nondeterministic collaborators (network, db, clock, randomness, filesystem) — don't mock the unit under test or pure logic, and don't over-mock to the point the test asserts nothing real.
  3. Keep doubles faithful to the real interface and reset them between tests so suites stay isolated and order-independent.
  4. Prefer a fake or stub over a strict call-asserting mock unless the interaction itself is the behavior being verified — brittle "was-called-with" assertions on incidental calls make refactors painful.
  5. After writing, show where the double is wired, what it returns/asserts, and the command to run the affected tests.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.