# Jest — Delightful JavaScript Testing Framework > Jest is a delightful JavaScript testing framework with a focus on simplicity. Zero-config for most JS/TS projects, snapshot testing, mocking, code coverage, and parallel test execution. Created by Facebook and used to test React, Instagram, and many large codebases. ## Install Save the content below to `.claude/skills/` or append to your `CLAUDE.md`: ## Quick Use ```bash npm i -D jest @types/jest ts-jest # Or for TypeScript projects npx ts-jest config:init ``` ```ts // sum.ts export function sum(a: number, b: number): number { return a + b; } // sum.test.ts import { sum } from "./sum"; describe("sum", () => { test("adds 1 + 2 to equal 3", () => { expect(sum(1, 2)).toBe(3); }); test("handles negative numbers", () => { expect(sum(-1, -2)).toBe(-3); }); }); ``` ```bash npx jest # Run all tests npx jest --watch # Watch mode npx jest --coverage # With coverage report ``` ## Intro Jest is a delightful JavaScript testing framework created by Facebook (now Meta). Zero-config for most React and TypeScript projects. Features include snapshot testing, built-in mocking, code coverage, parallel execution, and an intuitive API. Used to test React, Instagram, and many Meta properties. - **Repo**: https://github.com/jestjs/jest - **Stars**: 45K+ - **Language**: TypeScript - **License**: MIT ## What Jest Does - **Zero-config** — works out of the box for most JS/TS projects - **Snapshot testing** — capture and compare UI output - **Mocking** — `jest.fn()`, `jest.mock()`, `jest.spyOn()` - **Code coverage** — built-in Istanbul coverage - **Parallel execution** — tests run in isolated workers - **Watch mode** — re-run changed tests - **Matchers** — rich assertion library (`toBe`, `toEqual`, `toThrow`, `toMatchSnapshot`) - **Timer mocks** — fake timers for setTimeout/setInterval - **Async testing** — async/await, promises, callbacks ## Comparison | Runner | Speed | TS | ESM | Watch | |---|---|---|---|---| | Jest | Medium | Via ts-jest | Experimental | Yes | | Vitest | Fast | Native | Native | Yes | | Mocha | Medium | Via ts-node | Yes | Yes | | Node test runner | Fast | Via tsx | Yes | Yes | ## FAQ **Q: Jest vs Vitest?** A: Vitest is faster (Vite-powered), native ESM, and TS works without ts-jest. Vitest is recommended for new Vite projects. Jest has a larger ecosystem and more legacy projects. **Q: How to configure TypeScript?** A: Use the `ts-jest` transformer or `@swc/jest` (faster). Configure the `transform` field in `jest.config.ts`. ## Sources - Docs: https://jestjs.io - GitHub: https://github.com/jestjs/jest - License: MIT --- Source: https://tokrepo.com/en/workflows/jest-delightful-javascript-testing-framework-4240433c Author: AI Open Source