PROVIDER Β· the default testing framework of the React ecosystem
Jest
Jest is Meta's open-source JavaScript test framework running with zero config and bundling assertions, snapshots, and coverage where jsdom tests React components directly as the long-standing default.
Pros
Cons
Product Information
Detailed Notes
Overview
Jest was released by Meta in 2014 designed for React component testing, running with zero configuration, bundling assertions, snapshot testing, and coverage as the long-standing default for JavaScript unit tests.
For Programming Languages & Frameworks work the value is out-of-the-box operation with the broadest ecosystem, since the jsdom environment tests DOM and components directly, mocks and spies are comprehensive, snapshots suit UI regression, and tutorials, scaffolds, and community configs default to it.
See the current state, because Jest builds on CommonJS and Babel transforms making ESM and TypeScript projects fiddly, startup and run speed trail Vitest clearly, Meta shifted focus elsewhere, and new projects especially with Vite favour Vitest.
Core Strengths
- Zero configuration with built-in assertions, snapshots, and coverage
- A jsdom environment testing DOM and React components directly
- Mature mocks, spies, and module replacement
- Default support across tutorials and scaffolds with the most material
Product Ecosystem
Core
describe and it structure, expect assertions, snapshots, and watch mode.
Environment and mocks
The jsdom environment with jest.mock, fake timers, and spyOn.
Coverage and tooling
Coverage reports in lcov, text, or html with Testing Library integration.
Drawbacks
- CommonJS and Babel based with fiddly ESM and TypeScript setup
- Clearly slower than Vitest
- Slower feature development after Meta's focus shift
- Vite-era projects prefer Vitest
Use Cases
- React component and logic tests (β β β β β ) - Ecosystem default
- Existing CRA and Webpack projects (β β β β β ) - Ready configuration
- UI snapshot regression (β β β β ) - Snapshot mechanism
- New Vite and ESM projects (β β β ) - Choose Vitest
Pricing
| Plan | Price | Scope |
|---|---|---|
| Jest | $0 | MIT licensed, free |
| Testing Library companions | $0 | Open source and free |
| CI runtime cost | Platform billing | GitHub Actions and similar |
Entirely free with cost in CI time, since Jest runs slowly and large suites take minutes, and migrating to Vitest on Vite usually simplifies configuration and halves runtime.
FAQ
-
Jest or Vitest? Vitest for new projects especially with Vite, and Jest remains simpler for existing Webpack or CRA projects.
-
Are snapshots useful? They suit UI structure regression while large snapshots invite blind updates, so pair with behavioural assertions.
-
Can it test TypeScript? Yes through ts-jest or Babel transforms with more configuration than Vitest.
Code Examples
Behaviour assertions and snapshots
import { filterCheap } from './plans';
describe('filterCheap', () => {
it('keeps only plans below the threshold', () => {
const input = [{ name: 'HK', price: 99 }, { name: 'US', price: 59 }];
expect(filterCheap(input, 80)).toEqual([{ name: 'US', price: 59 }]);
});
it('matches the component snapshot', () => {
expect(render(<PlanCard name="HK" price={99} />)).toMatchSnapshot();
});
});
npx jest --watch runs only affected tests and --coverage prints a coverage report.
Mocking modules and timers
jest.mock('./api', () => ({ fetchPlans: jest.fn().mockResolvedValue([]) }));
it('shows a message when loading fails', async () => {
api.fetchPlans.mockRejectedValueOnce(new Error('boom'));
render(<PlanList />);
expect(await screen.findByText(/load failed/)).toBeInTheDocument();
});
Community & Resources
Communities and official channels
- Jest Site β Config, API, and migration guides
- GitHub jestjs/jest β Source, issues, and releases
- Stack Overflow #jestjs β Mocking and config answers
Learning resources and tools
- Jest Getting Started β Official quick start
- Testing Library β Assertions from a user's perspective
- Awesome Jest β Extensions and tooling