Internative Logo

What Is Jest? The JavaScript Testing Framework Explained

What Is Jest? The JavaScript Testing Framework Explained

Every JavaScript codebase reaches the point where changing one function quietly breaks another. Automated tests are how teams find that out before their users do, but for years writing them in JavaScript meant assembling a test runner, an assertion library, a mocking tool and a coverage reporter, then configuring all four to agree. Jest packages those pieces into one tool that works with little or no configuration, which is why it became the default test framework for React, React Native and much of the Node.js world.

This article explains what Jest is, how it runs tests, where it is used, when it is the right choice, and how it compares with Vitest, Mocha and browser-based E2E testing tools such as Cypress.

What is Jest?

Jest is an open-source testing framework for JavaScript and TypeScript. It includes a test runner, an assertion API (expect), mocking, snapshot testing and code coverage in one package, and it runs tests for front-end code, Node.js services and React Native apps alike.

Jest began inside Facebook as an internal tool for unit testing JavaScript. The company open-sourced it in May 2014: version 0.1.0 of the jest-cli package, described as "Painless JavaScript Unit Testing", was published on npm on 14 May 2014. The first versions were built on top of the Jasmine test framework and were known for automatically mocking every module a test imported. Later versions turned automatic mocking off by default and added snapshot testing, which made Jest the natural partner for React.

On 11 May 2022, Meta transferred Jest to the OpenJS Foundation, the home of projects such as Node.js and webpack, and ownership moved to the Jest core team. Jest 30, released on 4 June 2025, was the first major version in three years; it improved speed and memory use, dropped support for Node 14, 16, 19 and 21, and upgraded its browser-like environment to jsdom 26.

How Jest works

Test files and the runner. Jest finds files that end in .test.js, .spec.ts and similar patterns, or that live in a __tests__ folder. Each file contains describe blocks and test (or it) cases with expect assertions such as expect(total).toBe(42). The runner executes files in parallel across worker processes, and each test file runs in its own isolated module registry, so state does not leak between files.

Environments. By default tests run in a Node.js environment. For code that touches the DOM, the jsdom environment provides a browser-like document and window without starting a real browser, which keeps tests fast.

Transforms. Jest runs code through a transformer before executing it. With Babel, or with ts-jest, the same setup handles modern JavaScript, JSX and TypeScript. Native ECMAScript modules are supported, but that support is still marked experimental, which is one reason ESM-first projects look at alternatives.

Mocks and spies. jest.fn() creates a mock function that records its calls, jest.spyOn() watches an existing method, and jest.mock('./api') replaces a whole module. Fake timers let a test move time forward instead of waiting for real timeouts.

Snapshots. A snapshot test renders a component or serialises a value, stores the result in a file, and fails if a later run produces something different. It is a quick way to catch unintended changes in UI output, as long as the team reviews snapshot updates instead of accepting them blindly.

Key features

  • Zero or minimal configuration for most JavaScript and TypeScript projects.
  • Built-in assertions, mocks, spies and fake timers, so no extra libraries are needed for unit tests.
  • Snapshot testing for UI components and serialised output.
  • Code coverage reports with one flag, --coverage.
  • Parallel execution and watch mode, which reruns only the tests related to changed files.
  • A large ecosystem: React Testing Library, framework presets, custom matchers and reporters.

Where Jest is used

  • React and Next.js front ends, usually together with React Testing Library for component tests.
  • React Native apps, where the default project template ships with Jest, and teams add Detox for E2E tests on devices.
  • Node.js backends, such as Express and NestJS services, often paired with Supertest for HTTP-level tests. New NestJS projects now generate Vitest tests by default, but many existing ones run on Jest.
  • Shared libraries and SDKs that need fast, isolated unit tests on every commit.
  • CI pipelines, where jest --ci runs the suite on every pull request and fails the build when coverage or tests regress.

When to choose Jest, and when not to

Choose Jest when:

  • You want one tool for unit tests, mocks, snapshots and coverage with little setup.
  • The project uses React Native, or an existing React or Node.js setup, where Jest is the expected default.
  • You value a mature ecosystem and documentation that covers almost every edge case.
  • The codebase already has a large Jest suite; migrating it rarely pays off on its own.

Look elsewhere when:

  • The project is built with Vite and uses native ES modules. Vitest reuses the Vite pipeline, offers a largely Jest-compatible API and avoids a separate transform setup.
  • You need to test real browser behaviour across Chromium, Firefox and WebKit. Jest's jsdom is a simulation; Playwright or Cypress drive real browsers.
  • You want zero dependencies in a small Node.js package. The test runner built into Node.js (node:test) may be enough.

Jest and its alternatives

ToolTypeStrengthBest fit
JestUnit and integrationAll-in-one, huge ecosystemReact, React Native, Node.js
VitestUnit and integrationVite-native, fast, ESM-firstVite, Vue, Svelte and modern React apps
Mocha + ChaiUnit and integrationFlexible, pick your own partsTeams that want to assemble their stack
node:testUnitBuilt into Node.jsSmall Node.js libraries
Cypress / PlaywrightE2E (browser)Real browsers, user flowsTesting the app as a user sees it

The question people ask most is Jest vs Vitest. Vitest was designed to feel like Jest, so most describe, test and expect code moves over with few changes; the difference is in the pipeline. In a Vite project, Vitest uses the same configuration and transforms as the app, which removes duplicated setup and usually runs faster. In a React Native or older webpack project, Jest remains the path of least resistance.

Jest vs Cypress is not really a competition. Jest tests functions and components in isolation, quickly and in large numbers; Cypress and Playwright test whole user flows in a real browser, more slowly and in smaller numbers. Most mature projects run both: many fast Jest tests at the bottom, a few E2E tests at the top. We describe how tests fit into delivery pipelines in DevOps and CI/CD: continuous improvement in software development.

How we use Jest at Internative

We use Jest to keep code quality and reliability consistent across front-end and back-end systems. Its speed, clear error reports and smooth integration with modern frameworks support a testing practice that scales with the codebase and stays maintainable, and its tests run in the same CI pipelines that build and ship our applications.

If you are building a product and want a test strategy that catches regressions before release, our custom software development team can help you set it up.

Frequently asked questions

What is Jest used for?

Jest is used to write and run automated tests for JavaScript and TypeScript code: unit tests for functions, component tests for React and React Native, integration tests for Node.js services, and snapshot tests that catch unexpected changes in output.

Why use Vitest instead of Jest?

Vitest fits projects built with Vite. It shares the app's configuration and transforms, supports ES modules natively and is usually faster to start. Its API is largely compatible with Jest, so switching is mostly a configuration change. For React Native and many Node.js projects, Jest is still the default.

Which is better for testing, Cypress or Jest?

They test different things. Jest runs fast, isolated unit and component tests. Cypress runs E2E tests in a real browser, clicking through the app the way a user would. Most teams use Jest for the bulk of their tests and Cypress or Playwright for a smaller set of critical user flows.

What is a test framework?

A test framework is a tool that finds your tests, runs them and reports which passed and which failed. It usually provides a way to structure tests, an assertion API to check results and helpers such as mocks. Jest bundles all of these in one package.

How do you run a single test file in Jest?

Pass the file path or part of its name to Jest, for example npx jest src/cart.test.ts. To run only matching test names inside files, use -t "adds an item", and use watch mode with --watch to rerun tests as you edit.

Related services

Where this topic becomes an engagement.

Keep reading

The articles that follow this one.