jest
Jest is a delightful JavaScript testing framework with a focus on simplicity, created by Facebook. It works out of the box for most JavaScript projects with zer…
Installation
npm install -D jest
yarn add -D jest
pnpm add -D jest
Import
// jest tests use globals: describe, it, expect
Quick Example
describe('sum', () => {
it('adds 1 + 2 to equal 3', () => {
expect(1 + 2).toBe(3);
});
it('returns negative for negative input', () => {
expect(-1 + -2).toBe(-3);
});
});About jest
Jest is a delightful JavaScript testing framework with a focus on simplicity, created by Facebook. It works out of the box for most JavaScript projects with zero configuration, supporting test discovery, assertion matchers, mocking, code coverage, and snapshot testing. Jest runs tests in parallel using worker processes for speed, isolates each test file in its own environment to prevent state leakage, and includes a powerful mocking system that can mock functions, modules, timers, and entire libraries automatically. The framework provides built-in code coverage reporting using Istanbul, watch mode that re-runs only tests affected by changed files, and snapshot testing for capturing serialized output of React components or any data structure. Jest supports TypeScript through ts-jest or @swc/jest, async/await testing, custom matchers, and setup/teardown hooks at both the test and suite level. The expect assertion library offers rich matchers including toMatchObject, toThrow, toHaveBeenCalledWith, and asymmetric matchers for partial matching. Jest remains the most widely used JavaScript testing framework, particularly dominant in React projects.
Quick Facts
| Package | jest |
| Category | Testing |
| Weekly Downloads | 25M+ |
| License | MIT |
| Install | npm install -D jest |
Related Packages
Vitest is a blazing-fast unit testing framework powered by Vite, designed as a modern alternative to…
Mocha is a feature-rich JavaScript test framework that runs on Node.js and in the browser, providing…
Testing Library is a family of packages that helps you test UI components in a way that resembles ho…
Sinon.js provides standalone test spies, stubs, and mocks for JavaScript that work with any test fra…
Istanbul is the standard JavaScript code coverage tool that instruments your code to track which lin…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.