# Jest

> Jest unit testing conventions — configuration, describe/it structure, mocking, async tests, and coverage. Load when working with Jest test files or jest.config.*. Use when this capability is needed.

- Skill: `tomevault-io/jest-4` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/jest-4`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/jest-4/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/jest-4

---


Full standards in [jest.md](jest.md). Always-on summary:

**Structure:**
- One `describe(` per module/class; one `describe(` per method inside
- Test names complete the sentence: `it('returns null when user not found')`
- Use `expect(` for all assertions — Arrange-Act-Assert with blank lines between sections

**Setup / teardown:**
- `beforeEach(` to reset state before each test; call `jest.clearAllMocks(` in `beforeEach` to prevent cross-test pollution

**Mocking:**
- `jest.mock(` calls go at the top of the file, before imports take effect
- Use `mockReturnValue(` or `mockResolvedValue(` to control return values
- Mock at the system boundary (HTTP, DB, filesystem) — not internal functions
- `jest.spyOn()` for partial mocks where you want the real implementation for some calls
- Always restore mocks: use `jest.restoreAllMocks()` in `afterEach` or `restoreMocks: true` in config

**Async:**
- Always `return` or `await` promises — an unawaited assertion can silently pass
- Use `jest.useFakeTimers()` for `setTimeout`/`setInterval` tests; always call `jest.useRealTimers()` in `afterEach`

**Coverage:**
- Set thresholds in `jest.config.ts` — don't chase 100%; target branches and functions
- `/* istanbul ignore next */` — use sparingly with a comment explaining why

**Never:**
- `it.only()` or `describe.only()` merged to main — use `--testNamePattern` in dev
- Test implementation details — test behaviour observable from the outside
- Assertions inside loops — extract to helpers or use `test.each`

**Related skills:** Your frontend or backend layer (framework-specific setup), `mocking/msw` (HTTP mocking for integration tests)

---
> Source: [manikumarkv/devrunway-claude-plugin](https://github.com/manikumarkv/devrunway-claude-plugin) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-06-16 -->

