Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add skills/pramoddutta/qaskills/jest-mocking-patternsnpx skills add PramodDutta/qaskills --skill jest-mocking-patternsgit clone --depth 1 https://github.com/PramodDutta/qaskillsWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/pramoddutta/qaskills/jest-mocking-patterns)<a href="https://agentmods.dev/skills/pramoddutta/qaskills/jest-mocking-patterns"><img src="https://agentmods.dev/badge/skills/pramoddutta/qaskills/jest-mocking-patterns.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00044 | $0.02462 |
| Opus 5 | $0.00022 | $0.01231 |
| Sonnet 5 | $0.00009 | $0.00492 |
| Haiku 4.5 | $0.00004 | $0.00246 |
Grade A, and why
Jest Mocking Patterns scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Makes network callslowCapability
Not a fault in itself. Listed so you know the mod talks to something, and to what.
const { data } = await axios.get(`/api/users/${id}`); How it starts
The opening of the file, as written. The whole thing — 245 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Jest Mocking Patterns
This skill makes the agent mock dependencies in Jest deliberately and reversibly: stubbing functions with jest.fn, controlling return values with mockReturnValue/mockResolvedValue, replacing whole modules with jest.mock factories, and spying on real implementations with jest.spyOn (always restored). The guiding rule: mock the boundary, not the unit under test, and always reset state between tests so mocks never leak.
Use this skill when the agent needs to isolate code from the network, the clock, the filesystem, a database client, or any third-party module (axios, fs, a payment SDK).
Core Principles
- Mock at the boundary. Mock network/DB/3rd-party clients, not the function you are testing. If you mock the thing under test, the test proves nothing.
- Reset mocks between tests. Configure
clearMocks: true(or calljest.clearAllMocks()inbeforeEach) so call counts and implementations never bleed across tests. jest.mockis hoisted. Calls tojest.mock('module', factory)are lifted above imports. The factory cannot reference outer variables unless they are prefixedmock.- Prefer
spyOn+mockRestoreoverjest.mockwhen you only need to override one method and want the real implementation back afterward. - Type your mocks. Use
jest.mocked()(oras jest.Mock) so the mock API is type-checked and autocompletes. - Assert behavior, then interactions. Check the result first; use
toHaveBeenCalledWithto verify the boundary was called correctly.
Workflow / Patterns
Pattern 1 — jest.fn and controlling return values
jest.fn() is a recording stub. Drive it with mockReturnValue, mockResolvedValue, mockRejectedValue, or queue per-call values with mockReturnValueOnce.
test('jest.fn return value control', () => {
const calc = jest.fn();
calc.mockReturnValue(10); // default for every call
calc.mockReturnValueOnce(1).mockReturnValueOnce(2); // queued, then falls back
expect(calc()).toBe(1);
expect(calc()).toBe(2);
expect(calc()).toBe(10);
expect(calc).toHaveBeenCalledTimes(3);
});
test('async return values', async () => {
const fetchUser = jest.fn<Promise<{ id: number }>, [number]>();
fetchUser.mockResolvedValue({ id: 1 });
await expect(fetchUser(1)).resolves.toEqual({ id: 1 });
fetchUser.mockRejectedValueOnce(new Error('not found'));
await expect(fetchUser(99)).rejects.toThrow('not found');
});
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2d ago First seen · 245 lines · 44 tokens per session scan A 8f0556dc4d94
Jest Mocking Patterns is a skill published in the GitHub repository PramodDutta/qaskills (217 stars, last pushed 6d ago), licensed MIT. It adds 44 tokens to every session and 2,462 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.
Other skills, from other repositories
jest-expert
Expert in Jest unit testing framework, mocks, snapshots, coverage reports, watch mode, and custom matchers. Use when the user mentions testing, unit testing, JavaScript, QA, mocking, or snapshots, or when the task involves Jest Framework, Test Structure, Advanced Features, or Basic Unit Tests.
Unit Test Scaffold (TypeScript)
Generate TypeScript unit test skeletons (Jest/Vitest) from specifications.
pytest
Advanced Python unit testing framework for customer support tech enablement, covering FastAPI, SQLAlchemy, PostgreSQL, async operations, mocking, fixtures, parametrization, coverage, and comprehensive testing strategies for backend support systems.
test-unit-generator
Activate when writing, generating, or refactoring unit test suites in TypeScript, JavaScript, or Python using Vitest, Jest, or Pytest — trigger phrasings include "write unit tests for this function", "create a Vitest test suite", "test edge cases for this utility", "mock this API in Jest", "increase test coverage to…
Jest Unit Test
Write unit tests with Jest including mocking, assertions, and test organization.
rust-testing
Rust testing patterns including unit tests, integration tests, async testing, property-based testing, mocking, and coverage. Follows TDD methodology.