Jest: JavaScript testing framework with zero configuration

Jest (August 2014, Facebook, stabilised after 2016): JavaScript/TypeScript testing framework with zero config, snapshot testing, built-in mocking, watch mode. React standard and basis of Vitest.

Open SourceWeb JestFacebookMetaTestingJavaScriptReactOpen SourceWeb

A framework for React

Facebook develops Jest internally to test its own JavaScript codebases — React included. Before Jest, Node testing is fragmented: Mocha + Chai + Sinon, Jasmine, AVA, Tape each with different syntax and assembly. Configuring and running takes a lot of setup.

The release

Jest is open-sourced by Facebook in 2014; versions 14.0 (May 2016) and 16.0 (September 2016) mark the transformation into a mass framework with adoption by Create React App. Main author: Christoph Nakazawa. MIT licence.

test('sum adds numbers', () => {
  expect(sum(1, 2)).toBe(3);
});

test('user snapshot', () => {
  expect(renderUser()).toMatchSnapshot();
});

Features

  • Zero config — works out-of-box with ES modules, JSX, TypeScript (via babel-jest)
  • Integrated assertion libraryexpect() with .toBe(), .toEqual(), .toMatch(), .toThrow() matchers
  • Built-in mockingjest.fn(), jest.mock() for modules
  • Snapshot testing — serialises output and compares on subsequent runs
  • Parallel execution — worker pool for parallel tests
  • Code coverage — integrated Istanbul with --coverage
  • Watch mode — interactive, re-runs only affected tests
  • jsdom environment integrated for DOM tests

Testing React

Around Jest the React testing ecosystem is growing: Enzyme (Airbnb) for component-level testing remains the prevailing choice, with alternatives emerging over time.

Competitors

  • Mocha + Chai — historical, more configurable and less opinionated
  • AVA — concurrent, minimal
  • Jasmine — older

In the Italian context

Jest is becoming the standard choice of Italian React teams: headless e-commerce, fintech and first digital-PA projects are adopting it as default.


References: Jest (Facebook, Open Source 2014). Christoph Nakazawa lead. MIT licence.

Need support? Under attack? Service Status
Need support? Under attack? Service Status