jest-patterns

jest-patterns is a skill for Claude Code, Codex from vladkesler/initrunner. It costs 34 tokens per session (765 once invoked), scanned A, original, Apache-2.0.

A collection of testing patterns for Jest and Vitest, JavaScript and TypeScript tools that run automated tests. It covers test structure, value checks, mocks, snapshots, and asynchronous code.

In plain words
What is it for?
Use it when writing or reviewing Jest or Vitest tests, including tests with mocked functions, grouped cases, or asynchronous operations.
Why use it?
It gives you consistent ways to organize tests and check both simple results and code that waits for other work.

Skill for Claude CodeCodex

Install

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.

agentmods
npx agentmods add skills/vladkesler/initrunner/jest-patterns
Any agent
npx skills add vladkesler/initrunner --skill jest-patterns
Clone the repo
git clone --depth 1 https://github.com/vladkesler/initrunner

Made for: Claude Code, Codex.

Wrote 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.

agentmods badge for jest-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/vladkesler/initrunner/jest-patterns.svg)](https://agentmods.dev/skills/vladkesler/initrunner/jest-patterns)
Your own site
<a href="https://agentmods.dev/skills/vladkesler/initrunner/jest-patterns"><img src="https://agentmods.dev/badge/skills/vladkesler/initrunner/jest-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 34 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 765 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

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.

ModelPer sessionOnce invoked
Fable 5 $0.00034 $0.00765
Opus 5 $0.00017 $0.00382
Sonnet 5 $0.00007 $0.00153
Haiku 4.5 $0.00003 $0.00076

Measured 4d ago against content hash 42a3de90622f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

jest-patterns scanned grade A with 0 findings 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 4d 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.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

examples/roles/unit-tester/skills/jest-patterns/SKILL.md · 81 lines

How it starts

The opening of the file, as written. The whole thing — 81 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Jest and Vitest testing patterns for JavaScript and TypeScript projects.

When to activate

Use this skill when the project has jest.config.*, vitest.config.*, a package.json listing jest or vitest as a dependency, or test files matching *.test.{js,ts,tsx} or *.spec.{js,ts,tsx}.

Test file structure

  • Use describe blocks to group related tests by feature or function.
  • Use it (or test) blocks for individual test cases -- each one should describe a single behavior.
  • Nest describe blocks for sub-scenarios (e.g. describe("when input is empty", ...) inside describe("parseConfig", ...)).
  • Use beforeEach / afterEach for per-test setup and teardown.
  • Use beforeAll / afterAll sparingly -- only for expensive one-time setup like database connections.

Matchers

  • toBe(value) -- strict equality (===).
  • toEqual(value) -- deep equality for objects and arrays.
  • toMatchObject(subset) -- partial object matching.
  • toThrow(error?) -- verify that a function throws.
  • toHaveBeenCalledWith(args) -- assert mock was called with specific args.
  • toMatchSnapshot() -- snapshot testing for serializable output.
  • toContain(item) -- array/string includes check.
  • toHaveLength(n) -- array or string length check.

Mocking

  • jest.fn() / vi.fn() -- create a mock function with call tracking.
  • jest.mock("module") / vi.mock("module") -- replace an entire module with auto-mocked version.
  • jest.spyOn(obj, "method") / vi.spyOn(obj, "method") -- spy on a method while keeping original implementation unless overridden.
  • mockResolvedValue(val) -- shorthand for mocking async functions that return promises.
  • mockImplementation(fn) -- provide a custom implementation.

Async testing

  • Use async/await in test functions for promise-based code.
  • .resolves / .rejects matchers: await expect(fetchData()).resolves.toEqual(expected).
  • Always await assertions on promises -- forgetting await causes silent passes.

Read the full file on GitHub · 81 lines

Changes

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.

  1. 4d ago First seen · 81 lines · 34 tokens per session scan A 42a3de90622f

Subscribe to this mod's changes

jest-patterns is a skill published in the GitHub repository vladkesler/initrunner (41 stars, last pushed 6d ago), licensed Apache-2.0. It adds 34 tokens to every session and 765 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.