jest

jest is a cursor rule for Cursor from nedcodes-ok/cursor-doctor. It costs 978 tokens per session, scanned A, a copy of jest, MIT.

A set of rules for writing Jest tests, where Jest is a JavaScript and TypeScript testing tool. It covers test structure, matchers, mocking, asynchronous tests, and test independence.

In plain words
What is it for?
Use it when creating or reviewing unit tests with `describe` and `it`, Arrange-Act-Assert setup, matchers, mocks, and asynchronous code.
Why use it?
It reduces unclear, fragile, or order-dependent tests by giving developers consistent ways to organize checks and compare results.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc). Also seen: mentions Cursor.

Good fit Use it when creating or reviewing unit tests with describe and it, Arrange-Act-Assert setup, matchers, mocks, and asynchronous code.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/nedcodes-ok/cursor-doctor/jest
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.

Clone the repo
git clone --depth 1 https://github.com/nedcodes-ok/cursor-doctor

Made for: Cursor.

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

README.md
[![agentmods](https://agentmods.dev/badge/rules/nedcodes-ok/cursor-doctor/jest/github.svg)](https://agentmods.dev/rules/nedcodes-ok/cursor-doctor/jest)
Your own site
<a href="https://agentmods.dev/rules/nedcodes-ok/cursor-doctor/jest"><img src="https://agentmods.dev/badge/rules/nedcodes-ok/cursor-doctor/jest/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for jest

Your own site · 80×15
<a href="https://agentmods.dev/rules/nedcodes-ok/cursor-doctor/jest"><img src="https://agentmods.dev/badge/rules/nedcodes-ok/cursor-doctor/jest.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 978 This file is loaded in full into every session.
When invoked 978 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin 100% copy Near-identical to another mod 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.1 $0.00978 $0.00978
Opus 5.5 $0.00391 $0.00391
Sonnet 5.5 $0.00196 $0.00196
Haiku 4.5 $0.00098 $0.00098

Measured 1mo ago against content hash 8ace8a931584, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

jest 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 1mo 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.

Origin

This is a copy

100% identical to jest — 0 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

pro-kit/templates/tools/jest.mdc · 48 lines

How it starts

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

Jest Cursor Rules

You are an expert in Jest testing (v29+). Follow these rules:

Structure

  • One test file per source file: user.service.ts → user.service.test.ts. Colocate tests next to source, not in a separate __tests__/ tree
  • describe() for grouping related behaviors. Nest describes for sub-behaviors: describe('UserService') → describe('findById')
  • it() with descriptive names that read as sentences: it("returns null when user not found") — not it("test1") or it("should work")
  • Tests must be independent — no shared mutable state between test cases. If test B depends on test A running first, both tests are broken
  • Arrange-Act-Assert pattern in every test: set up data, call the thing, check the result. One logical assertion per test (multiple expect calls checking one behavior is fine)

Matchers

  • .toBe() for primitives and reference equality. .toEqual() for deep equality on objects/arrays — .toBe({a:1}) fails because it's a different object reference
  • .toMatchObject() for partial matching — don't over-specify with .toEqual() when you only care about 3 of 10 fields. Less brittle when the shape changes
  • .toThrow() requires wrapping in a function: expect(() => fn()).toThrow() not expect(fn()).toThrow() — this is the #1 gotcha
  • .toHaveBeenCalledWith(expect.objectContaining({...})) for partial argument matching on mocks
  • .toMatchInlineSnapshot() over .toMatchSnapshot() for small outputs — inline snapshots keep the expected value right in the test file, no separate .snap file to maintain

Mocking

  • jest.fn() for standalone mock functions. jest.spyOn(object, 'method') to wrap an existing method while keeping the original accessible via .mockRestore()
  • jest.mock("module") at the top level — Jest hoists it above imports automatically. Inside the mock factory, you can't reference variables from the outer scope (they're not initialized yet)
  • jest.mocked(fn) for TypeScript: wraps the function type so autocomplete and type-checking work on mock methods (.mockReturnValue, .mockResolvedValue)
  • jest.clearAllMocks() in beforeEach — resets call counts and return values. jest.restoreAllMocks() also undoes spyOn replacements. Pick one and be consistent
  • Mock at the boundary (HTTP client, database, file system), not internal functions — testing the wiring between your own functions gives you change-detector tests, not confidence

Read the full file on GitHub · 48 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. 1mo ago First seen · 48 lines · 978 tokens per session scan A 8ace8a931584

Subscribe to this mod's changes

jest is a cursor rule published in the GitHub repository nedcodes-ok/cursor-doctor (9 stars, last pushed 7mo ago), licensed MIT. It adds 978 tokens to every session, about $0.0039 per session on Opus 5.5. A static security scan graded it A with 0 findings. It is 100% identical to jest, differing in 0 lines, and is treated as a copy.