jest
Skill15 starsChanged 43 days agoMITView on GitHub
Expert Jest testing assistance covering unit testing, snapshot testing, mocking, and coverage reports. Use when writing tests for JavaScript/TypeScript, React, Node.js, or Next.js applications.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- anivar/jest-skilltheir own version, first seen Nov 3, 2026
- Mane087/IA-Skillstheir own version, first seen Nov 1, 2026
- Mindrally/skillstheir own version, first seen Oct 8, 2026
- christopher-buss/skillstheir own version, first seen May 13, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- Mindrally/skills★ 275same name
- anivar/jest-skill★ 9same name
- christopher-buss/skills★ 8same name
- Mane087/IA-Skills★ 4same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository350 other files it gives its agents.
- airflowSkill
- catboostSkill
- claudeSkill
- comfyuiSkill
- cursor-aiSkill
- dalleSkill
- daskSkill
- dbtSkill
- deepseekSkill
- fastaiSkill
- geminiSkill
- github-copilotSkill
- huggingfaceSkill
- jaxSkill
- jupyterSkill
- kerasSkill
- langchainSkill
- lightgbmSkill
- llamaindexSkill
- llamaSkill
- matplotlibSkill
- midjourneySkill
- mistralSkill
- mlflowSkill
- nltkSkill
- numpySkill
- ollamaSkill
- openai-gptSkill
- opencvSkill
- pandasSkill
- perplexitySkill
- plotlySkill
- polarsSkill
- pytorchSkill
- raySkill
- scikit-learnSkill
- seabornSkill
- spacySkill
- sparkSkill
- stable-diffusionSkill
- tensorflowSkill
- vaexSkill
- weights-biasesSkill
- whisperSkill
- xgboostSkill
- api-gatewaySkill
- clean-architectureSkill
- cqrsSkill
- domain-driven-designSkill
- event-drivenSkill
- event-sourcingSkill
- graphqlSkill
- grpcSkill
- hexagonalSkill
- microservicesSkill
- modular-monolithSkill
- monolithSkill
- rest-apiSkill
- sagaSkill
- serverlessSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
5 rules. 0 are common, 1 is distinctive, and 4 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 94
Use jest.mock and jest.spyOn:
- Very specific: line 118
Use @swc/jest for Fast TypeScript Compilation: Replace slow ts-jest with SWC compiler to dramatically accelerate execution.
- Very specific: line 119
Use test.each for Table-Driven Test Cases: Consolidate repetitive test scenarios into parameterized tables.
- Distinctive: line 120
Keep Snapshots Small: Avoid snapshotting massive DOM trees.
- Very specific: line 126
Leave hanging asynchronous promises: Always return promises or await async calls to avoid unhandled rejections.
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Jest
Jest is a delightful JavaScript Testing Framework with a focus on simplicity. It works with projects using: Babel, TypeScript, Node, React, Angular, Vue, and more.
When to Use
- JavaScript & TypeScript Unit Testing: Standard, battery-included test runner for React, Node.js, and legacy frontend projects.
- Snapshot Testing: Freezing and asserting on large rendered component output, GraphQL responses, or JSON configurations.
- Comprehensive Mocking Engine: Spying on, mocking, and stubbing functions, timers, and entire modules with
jest.mock(). - Code Coverage Reporting: Generating built-in Istanbul code coverage metrics without external plugins.
Quick Start
// sum.js
function sum(a, b) {
return a + b;
}
module.exports = sum;
// sum.test.js
const sum = require("./sum");
test("adds 1 + 2 to equal 3", () => {
expect(sum(1, 2)).toBe(3);
});Core Concepts
Module Mocking & Function Spies (jest.fn(), jest.mock())
Replaces dependencies with mock implementations:
// service.test.ts
import { sendWelcomeEmail } from "./mailer";
import { registerUser } from "./user.service";
jest.mock("./mailer", () => ({
sendWelcomeEmail: jest.fn().mockResolvedValue(true),
}));
test("sends welcome email upon registration", async () => {
const result = await registerUser("test@example.com");
expect(result.success).toBe(true);
expect(sendWelcomeEmail).toHaveBeenCalledWith("test@example.com");
expect(sendWelcomeEmail).toHaveBeenCalledTimes(1);
});Fake Timers for Asynchronous Delays
Fast-forwards debounce timers, intervals, and timeouts instantaneously:
test("debounced search triggers after 300ms", () => {
jest.useFakeTimers();
const searchMock = jest.fn();
triggerDebouncedSearch(searchMock, "query");
expect(searchMock).not.toHaveBeenCalled();
// Fast forward clock
jest.advanceTimersByTime(300);
expect(searchMock).toHaveBeenCalledWith("query");
jest.useRealTimers();
});Snapshot Assertions
Detects unintended regressions in complex structures:
test("matches expected invoice schema snapshot", () => {
const invoice = generateInvoiceTemplate();
expect(invoice).toMatchSnapshot();
});Common Patterns
Mocking External Modules and Spying on Calls
Problem: Unit tests hitting third-party SDKs or database clients slow down test runs and produce side effects.
Solution:
Use jest.mock and jest.spyOn:
import axios from "axios";
import { fetchUserData } from "./userService";
jest.mock("axios");
const mockedAxios = axios as jest.Mocked<typeof axios>;
test("fetches successfully data from an API", async () => {
const data = { id: 1, name: "John" };
mockedAxios.get.mockResolvedValueOnce({ data });
const result = await fetchUserData(1);
expect(result).toEqual(data);
expect(mockedAxios.get).toHaveBeenCalledWith("/api/users/1");
});Best Practices
Do:
- Clear Mocks Between Tests: Enable
clearMocks: trueinjest.config.jsto prevent call count contamination across tests. - Use
@swc/jestfor Fast TypeScript Compilation: Replace slowts-jestwith SWC compiler to dramatically accelerate execution. - Use
test.eachfor Table-Driven Test Cases: Consolidate repetitive test scenarios into parameterized tables. - Keep Snapshots Small: Avoid snapshotting massive DOM trees; snapshot focused component states and data contracts.
Don't:
- Blindly update snapshots (
-u): Review snapshot diffs carefully before accepting changes to prevent approving bugs. - Mock what you don't own: Avoid mocking third-party libraries excessively; prefer integration tests with real adapters where possible.
- Leave hanging asynchronous promises: Always return promises or
awaitasync calls to avoid unhandled rejections.
Troubleshooting
| Error | Cause | Solution |
Cannot use import statement outside a module | Jest attempting to execute ESM files without proper Babel/ts-jest transform. | Configure ts-jest or set "transform": {} in jest.config.js. |
A worker process has failed to exit gracefully | Open handles, database connections, or active timers remaining. | Run with --detectOpenHandles and close connections in afterAll. |
Snapshot mismatch error | Intended UI or markup change failed snapshot assertion. | Review diff and update snapshots with jest -u. |
References
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

