API Reference

Jest

Delightful JavaScript testing framework with a zero-config setup, snapshot testing, and built-in coverage.

Official Documentation ↗
CompatibilityThis documentation covers version v30.5.2. Check the official docs for the latest API surface.

Installation

npmnpm install --save-dev jest

Methods

Jest provides a runner, assertion library, and mocking system in one package, with parallel workers by default.

Key Features

  • Zero-config discovery of test and spec files
  • Built-in snapshot and mock utilities
  • V8 coverage with no extra instrumentation

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://jestjs.io/docs/getting-started · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:30.279Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

FAQ

When should I use toBe versus toEqual?
toBe checks reference identity for primitives and objects, while toEqual performs a deep structural comparison. Use toBe for numbers and strings.
How do I mock a module?
Call jest.mock("./module") at the top of the file, then control the implementation with jest.mocked(fn).mockReturnValue.
Why is my snapshot failing after a refactor?
Snapshots capture exact output. Review the diff and run jest -u to update intentionally, but never blind-update without reading the change.