mane087/ia-skills/jest
Claude Code and agent skill by mane087/ia-skills
Trust tier 3
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Source check pending
Checking that the SKILL.md file is still in the repository.
Jest testing patterns and best practices for modern TypeScript/JavaScript projects. Trigger: Writing, refactoring, or reviewing Jest unit/integration tests (matchers, async, mocks, timers, snapshots, setup/teardown).
Install
npx vskill@latest install mane087/ia-skills/jestSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as mane087/ia-skills/jest.
When to Use
Use this skill when you are:
- Adding or refactoring Jest tests.
- Designing a mocking strategy (unit vs integration boundaries).
- Testing async code (Promises, async/await, callbacks).
- Testing time-dependent logic (timers, debouncing, polling).
- Introducing snapshots or maintaining existing snapshots.
- Standardizing setup/teardown and test isolation.
Critical Patterns
1) Determinism and isolation (MUST)
- MUST keep tests deterministic: no real network, no real time, no shared global mutable state.
- MUST isolate side effects:
- Prefer dependency injection.
- Reset/clear mocks between tests.
- Use setup/teardown hooks (
beforeEach,afterEach, etc.). (archive.jestjs.io)
2) Arrange / Act / Assert (MUST)
- MUST structure each test as:
- Arrange (inputs + dependencies)
- Act (execute)
- Assert (observable outcome)
- Avoid “mega tests” that validate many behaviors at once.
3) Matchers: be precise (MUST)
- MUST choose the most precise matcher:
toBefor exact equality (usesObject.is).toEqualfor deep equality (objects/arrays).toBeCloseTofor floats.toThrowrequires wrapping the call in a function. (archive.jestjs.io)
4) Async tests: don’t leak promises (MUST)
- MUST test async code using one of these correct patterns:
- Return the Promise
- Use
async/await - Use
donecallback only for legacy callback APIs
- MUST assert errors explicitly:
await expect(promise).rejects.toThrow(...)- or
return expect(promise).rejects...
- MUST prevent false positives:
- Use
expect.assertions(n)orexpect.hasAssertions()when appropriate. (archive.jestjs.io)
5) Setup/teardown: keep state clean (MUST)
- MUST use lifecycle hooks:
beforeEach/afterEachfor per-test setup/cleanup.beforeAll/afterAllfor expensive one-time setup.
- MUST keep cleanup symmetrical (what you create, you destroy). (archive.jestjs.io)
6) Mocking strategy: mock boundaries, not implementation details (MUST)
- MUST prefer mocking system boundaries:
- HTTP, DB, filesystem, timers, external SDKs.
- SHOULD avoid mocking internal helpers if behavior can be tested through public API.
- MUST prefer
jest.spyOnwhen you want to observe/override a real method. - MUST understand module mocks:
jest.mock()replaces a module.- manual mocks live in
__mocks__/. - use
jest.requireActual()when you need partial mocking. (archive.jestjs.io)
7) Mock functions: verify behavior, not noise (MUST)
- MUST assert the important interactions:
toHaveBeenCalledTimes,toHaveBeenCalledWith,toHaveBeenNthCalledWith.
- MUST keep call assertions focused (avoid over-specifying order unless it matters).
- MUST reset mock state between tests (
clearAllMocks/resetAllMocks/restoreAllMocks) according to repo policy. (archive.jestjs.io)
8) Timers: use fake timers for time-based logic (MUST)
- MUST use
jest.useFakeTimers()for debounce/throttle/polling logic. - MUST advance time explicitly (
advanceTimersByTime,runAllTimers). - MUST restore real timers after the test to avoid cross-test contamination. (archive.jestjs.io)
9) Snapshots: only for stable output (SHOULD)
- SHOULD use snapshots for stable, meaningful serialized output.
- SHOULD NOT snapshot large or frequently-changing structures.
- MUST keep snapshots small; prefer targeted assertions when possible.
- Use inline/property matchers to reduce brittleness. (archive.jestjs.io)
10) Platform/environment: choose correctly (MUST)
- MUST select the correct
testEnvironment: nodefor backend/library code.jsdomfor DOM-dependent code.
- MUST avoid accidental DOM dependencies in node tests. (archive.jestjs.io)
Code Examples
Matchers (precision)
Async (preferred patterns)
Setup/teardown + cleanup
Spies and module mocks (safe partial mocking)
Timers (debounce)
Snapshots (small and intentional)
Commands
Resources
- Matchers / expect (precision and choosing the right matcher). (archive.jestjs.io)
- Async testing (promises, async/await, callbacks, assertions count). (archive.jestjs.io)
- Setup & teardown (hooks and isolation). (archive.jestjs.io)
- Mock functions & API (
jest.fn, call assertions, mock APIs). (archive.jestjs.io) - Manual & class mocks (
__mocks__, module/class mocking patterns). (archive.jestjs.io) - Timers (fake timers, advancing time). (archive.jestjs.io)
- Snapshots (when to use and how to keep them stable). (archive.jestjs.io)
- Mocking best practices (boundary-first mocking strategy). (medium.com)
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/jest/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/mane087/ia-skills/jest)