The CheckOps Engineer home

Tools directory

J

The CheckOps Engineer

Jest

Jest is a free, open-source JavaScript test runner with zero-config defaults, mocks, and snapshot testing.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

Introduction

Jest is a JavaScript test runner for unit and component tests in Node.js. It started at Meta and is maintained as an MIT-licensed project at jestjs/jest. Many projects run with no config file: Jest discovers *.test.js and *.spec.js files, provides describe, it, and expect, and executes files in parallel worker processes.

The runner includes function and module mocks, fake timers, snapshot comparisons, and coverage through Istanbul or V8. TypeScript usually needs a transform (babel-jest, ts-jest, or the project’s compiler). Tests run in Node. DOM code typically uses jsdom, which is not a real browser.

Features

  1. Runner and matchers: describe, test / it, and expect ship in the same package, including equality, exception, and asymmetric matchers.
  2. Parallel workers: Test files run in worker processes. --watch reruns files affected by a change.
  3. Mocks: jest.fn, jest.mock, and manual mocks under __mocks__ replace modules without a second library.
  4. Fake timers: jest.useFakeTimers() controls setTimeout, setInterval, and Date so time-based code does not wait on the wall clock.
  5. Snapshots: toMatchSnapshot stores a serialized value and fails when the next run differs. Inline snapshots keep the expected string in the test file.
  6. Coverage: --coverage collects Istanbul or V8 coverage. Thresholds can fail the run from config.
  7. Projects: One config can declare several projects, setup files, a module name mapper, and testEnvironment of node or jsdom.
  8. CI reporters: Console output plus JSON and custom reporters. A JUnit reporter is a small extra package, not a separate product.

Pros

  1. One package for a typical Node library: Discovery, assertions, mocks, and watch mode are installed together.
  2. Examples match the runner: A large share of JavaScript unit-test snippets, including older React Testing Library docs, assume Jest matchers and jest.mock.
  3. Snapshot review is a diff: Intentional output changes are updated with -u and show up in code review.
  4. File isolation: Each test file gets its own module registry, which limits leaked state when mocks are reset.
  5. No seat fee: The MIT license allows private and public use. The cost is CI time and transform setup.

Cons

  1. jsdom is not a browser: Layout, navigation, and many web platform APIs are missing or stubbed. End-to-end checks belong in a browser runner.
  2. Transform cost on large UI suites: Babel or TypeScript transforms are slower than Vitest’s Vite pipeline on the same component tree.
  3. Native ESM needs extra config: Mixed CommonJS and ECMAScript module graphs often need extensionsToTreatAsEsm or a transform. Failures show up as syntax errors rather than a bundler warning.
  4. Snapshots drift: Large component snapshots fail on unrelated markup. They only help if reviewers reject unexplained updates.
  5. Monorepo config accumulates: Project lists, setup files, and mapper exceptions become their own maintenance surface.
npm install --save-dev jest
npx jest
npx jest --watch
npx jest --coverage
const { add } = require("./add");

test("adds two numbers", () => {
  expect(add(1, 2)).toBe(3);
});

Name that file add.test.js. Jest’s default pattern collects it. From Jest 28 onward, DOM tests need jest-environment-jsdom and testEnvironment: "jsdom".

Resources:

Pricing

  1. Free: Jest is MIT-licensed. There is no paid Jest tier and no hosted runner to subscribe to.
  2. CI is separate: You pay for the minutes that execute npx jest. Dashboards, flake tracking, and cloud traces are other products.
  1. Node libraries and backend units that already run in Node and do not use Vite’s transform pipeline.
  2. Suites that already use Jest mocks and snapshots, where a migration would rewrite working tests.
  3. React tests written against Jest, including Testing Library setups that call jest.fn and jest.mock.
  4. Projects that want a runner without installing Vite or a browser.

Conclusion

Jest is still the JavaScript unit runner most existing Node and React suites are written for. Keep it when the mocks, snapshots, and config are already in place. On a new Vite app, measure Vitest before paying for a second transform pipeline. Jest does not drive a real browser, so it does not replace Playwright, Cypress, or a device lab.