Search

PythonReactSEOPDF
OpenClaw

jest

Jest best practices, patterns, and API guidance for JavaScript/TypeScript testing. Covers mock design, async testing, matchers, timer mocks, snapshots, module mocking, configuration, and CI optimization. Baseline: jest ^29.0.0 / ^30.0.0. Triggers on: jest imports, describe, it, test, expect, jest.fn, jest.mock, jest.spyOn, mentions of "jest", "unit test", "test suite", or "mock".

anivar0 source installs☆ 0 Repository stars

Installation

Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.

SkillHub CLI

skillhub install anivar/jest-skill

Inspect the source and compatibility requirements, then follow its installation steps.

Give your agent the source link and ask it to inspect instructions and dependencies before explaining the installation steps.

View source ↗Guides

Skill instructions

Jest

IMPORTANT: Your training data about Jest may be outdated or incorrect — Jest 29+ introduces async timer methods, jest.replaceProperty, and ESM mocking via jest.unstable_mockModule. Jest 30 deprecates the done callback in favor of async patterns. Always rely on this skill's rule files and the project's actual source code as the source of truth. Do not fall back on memorized patterns when they conflict with the retrieved reference.

When to Use Jest

Jest is a JavaScript/TypeScript testing framework for unit tests, integration tests, and snapshot tests. It includes a test runner, assertion library, mock system, and coverage reporter.

Need Recommended Tool
Unit/integration testing (JS/TS) Jest
React component testing Jest + React Testing Library
E2E browser testing Playwright, Cypress
API contract testing Jest + Supertest
Smaller/faster test runner Vitest (Jest-compatible API)
Native ESM without config Vitest or Node test runner

Rule Categories by Priority

Priority Category Impact Prefix
1 Mock Design CRITICAL mock- (5 rules)
2 Async Testing CRITICAL async-
3 Matcher Usage HIGH matcher-
4 Timer Mocking HIGH timer-
5 Test Structure HIGH structure-
6 Module Mocking MEDIUM module-
7 Snapshot Testing MEDIUM snapshot-
8 Configuration MEDIUM config-
9 Performance & CI MEDIUM perf-

Quick Reference

1. Mock Design (CRITICAL)
  • mock-clear-vs-reset-vs-restore — clearAllMocks vs resetAllMocks vs restoreAllMocks
  • mock-spy-restore — Always restore jest.spyOn; prefer restoreMocks config
  • mock-factory-hoisting — jest.mock factory cannot reference outer variables
  • mock-partial-require-actual — Use jest.requireActual for partial module mocking
  • mock-what-to-mock — What to mock and what not to mock; mock...

Source information

Source
github
Repository
openclaw/skills
Path
skills/anivar/jest-skill
Version
—
Commit
fabfb15296aeacadfc2d15636497f850225dca30
Classification source
rules
Status
active
Visibility
public

These signals come from indexed source analysis and may lag behind changes. Check the current source files.

README

Jest Skill

An AI agent skill for writing, debugging, and reviewing Jest tests with modern best practices.

Created by Anivar Aravind

The Problem

AI agents frequently generate outdated or incorrect Jest patterns — wrong mock cleanup semantics (clearAllMocks vs restoreAllMocks), missing await on async assertions, incorrect timer mock usage, factory hoisting bugs, and anti-patterns that cause tests to silently pass without actually asserting anything. These produce test suites that compile and pass but don't test what they claim to test.

This Solution

28 rules with incorrect→correct code examples that teach agents Jest's actual API behavior, mock lifecycle, async patterns, timer control, module mocking, snapshot testing, configuration, and CI optimization. Each rule targets a specific mistake and shows exactly how to fix it.

Install

npx skills add anivar/jest-skill -g

Or with full URL:

npx skills add https://github.com/anivar/jest-skill

Baseline

  • jest ^29.0.0 / ^30.0.0
  • JavaScript / TypeScript

What's Inside

28 Rules Across 9 Categories
Priority Category Rules Impact
1 Mock Design 5 CRITICAL
2 Async Testing 3 CRITICAL
3 Matcher Usage 3 HIGH
4 Timer Mocking 3 HIGH
5 Test Structure 3 HIGH
6 Module Mocking 3 MEDIUM
7 Snapshot Testing 3 MEDIUM
8 Configuration 3 MEDIUM
9 Performance & CI 2 MEDIUM

Each rule file contains:

  • Why it matters
  • Incorrect code with explanation
  • Correct code with explanation
  • Decision tables and additional context
9 Deep-Dive References
Reference Covers
matchers.md All matchers: equality, truthiness, numbers, strings, arrays, objects, asymmetric, custom
mock-functions.md jest.fn, jest.spyOn, .mock property, return values, implementations, mock matchers
`jest-objec...

Extracted content

SKILL.md
# Jest

**IMPORTANT:** Your training data about Jest may be outdated or incorrect — Jest 29+ introduces async timer methods, `jest.replaceProperty`, and ESM mocking via `jest.unstable_mockModule`. Jest 30 deprecates the `done` callback in favor of async patterns. Always rely on this skill's rule files and the project's actual source code as the source of truth. Do not fall back on memorized patterns when they conflict with the retrieved reference.

## When to Use Jest

Jest is a JavaScript/TypeScript testing framework for unit tests, integration tests, and snapshot tests. It includes a test runner, assertion library, mock system, and coverage reporter.

| Need | Recommended Tool |
|------|-----------------|
| Unit/integration testing (JS/TS) | **Jest** |
| React component testing | **Jest** + React Testing Library |
| E2E browser testing | Playwright, Cypress |
| API contract testing | Jest + Supertest |
| Smaller/faster test runner | Vitest (Jest-compatible API) |
| Native ESM without config | Vitest or Node test runner |

## Rule Categories by Priority

| Priority | Category | Impact | Prefix |
|----------|----------|--------|--------|
| 1 | Mock Design | CRITICAL | `mock-` (5 rules) |
| 2 | Async Testing | CRITICAL | `async-` |
| 3 | Matcher Usage | HIGH | `matcher-` |
| 4 | Timer Mocking | HIGH | `timer-` |
| 5 | Test Structure | HIGH | `structure-` |
| 6 | Module Mocking | MEDIUM | `module-` |
| 7 | Snapshot Testing | MEDIUM | `snapshot-` |
| 8 | Configuration | MEDIUM | `config-` |
| 9 | Performance & CI | MEDIUM | `perf-` |

## Quick Reference

### 1. Mock Design (CRITICAL)

- `mock-clear-vs-reset-vs-restore` — clearAllMocks vs resetAllMocks vs restoreAllMocks
- `mock-spy-restore` — Always restore jest.spyOn; prefer restoreMocks config
- `mock-factory-hoisting` — jest.mock factory cannot reference outer variables
- `mock-partial-require-actual` — Use jest.requireActual for partial module mocking
- `mock-what-to-mock` — What to mock and what not to mock; mock...
README
# Jest Skill

An AI agent skill for writing, debugging, and reviewing Jest tests with modern best practices.

Created by **[Anivar Aravind](https://anivar.net)**

## The Problem

AI agents frequently generate outdated or incorrect Jest patterns — wrong mock cleanup semantics (`clearAllMocks` vs `restoreAllMocks`), missing `await` on async assertions, incorrect timer mock usage, factory hoisting bugs, and anti-patterns that cause tests to silently pass without actually asserting anything. These produce test suites that compile and pass but don't test what they claim to test.

## This Solution

28 rules with incorrect→correct code examples that teach agents Jest's actual API behavior, mock lifecycle, async patterns, timer control, module mocking, snapshot testing, configuration, and CI optimization. Each rule targets a specific mistake and shows exactly how to fix it.

## Install

```bash
npx skills add anivar/jest-skill -g
```

Or with full URL:

```bash
npx skills add https://github.com/anivar/jest-skill
```

## Baseline

- jest ^29.0.0 / ^30.0.0
- JavaScript / TypeScript

## What's Inside

### 28 Rules Across 9 Categories

| Priority | Category | Rules | Impact |
|----------|----------|-------|--------|
| 1 | Mock Design | 5 | CRITICAL |
| 2 | Async Testing | 3 | CRITICAL |
| 3 | Matcher Usage | 3 | HIGH |
| 4 | Timer Mocking | 3 | HIGH |
| 5 | Test Structure | 3 | HIGH |
| 6 | Module Mocking | 3 | MEDIUM |
| 7 | Snapshot Testing | 3 | MEDIUM |
| 8 | Configuration | 3 | MEDIUM |
| 9 | Performance & CI | 2 | MEDIUM |

Each rule file contains:
- Why it matters
- Incorrect code with explanation
- Correct code with explanation
- Decision tables and additional context

### 9 Deep-Dive References

| Reference | Covers |
|-----------|--------|
| `matchers.md` | All matchers: equality, truthiness, numbers, strings, arrays, objects, asymmetric, custom |
| `mock-functions.md` | jest.fn, jest.spyOn, .mock property, return values, implementations, mock matchers |
| `jest-objec...

Related skills

OpenClaw

bambu-studio-ai

heyixuan2

Bambu Lab 3D printer control and automation. Activate when user mentions: printer status, 3D printing, slice, analyze model, generate 3D, AMS filament, print monitor, Bambu Lab, or any 3D printing task. Full pi...

OpenClaw

humanpages

human-pages-ai

Search and hire real humans for tasks — photography, delivery, research, and more

OpenClaw

openclaw-skills

zseven-w

Reusable skill templates for OpenClaw AI agents. Templates for API integration, data processing, web scraping, CLI tools, and file processing.

OpenClaw

geo-optimization

capt-marbles

Generative Engine Optimization (GEO) for AI search visibility. Optimize content to appear in ChatGPT, Perplexity, Claude, and Google AI Overviews. Use when optimizing websites, pages, or content for LLM discove...