Jest
Jest is a JavaScript test runner from the Jest project: it discovers files, runs test/expect blocks, and ships mocks, snapshots, and coverage. It is still widely used, especially in React apps.
Detailed Explanation
A test runner's job is to find files (*.test.js, *.spec.ts), execute them, and report failures. Jest does that with a CLI (npx jest), a config (jest.config.js or the jest key in package.json), and a globals API: describe, test (alias it), expect, beforeEach, afterEach, beforeAll, afterAll.
Jest runs tests in Node by default, in parallel worker processes. Browser APIs are not there unless you install a environment (jsdom is the usual one for DOM tests). test.each is table-driven tests. test.only / test.skip focus and ignore. Async tests return a promise or use async/await; a forgotten await is a false pass.
The bundled mock system is jest.fn(), jest.spyOn, and jest.mock("module"). Module mocks are hoisted (via the Jest transformer) so they apply before imports. That is powerful and surprising if you come from a runner that does not hoist. Snapshots store a serialised value in a .snap file; they are for stable UI or large objects, not for values that change every run.
Jest 27+ defaulted the test runner to jest-circus and later aligned more with ESM. ESM support exists (extensionsToTreatAsEsm) and is still rougher than Vitest's native Vite ESM path. Many codebases stay on CJS Jest or migrate to Vitest.
What it costs you: a custom module system (hoisted mocks, haste map), slower cold starts than Vitest in Vite projects, and snapshot noise in review. Config for TypeScript, path aliases, and ESM can be a weekend.
Reach for Jest when the repo already has it, or when you want one tool with mocks and coverage included. Reach for Vitest when the app is already on Vite. Reach for Node's built-in node:test when you want zero extra runner.
Code Examples
function add(a, b) {
return a + b;
}
describe("add", () => {
test("sums two numbers", () => {
expect(add(2, 3)).toBe(5);
});
test("is not concatenation", () => {
expect(add(1, 1)).not.toBe("11");
});
});test("async", async () => {
const value = await Promise.resolve(7);
expect(value).toBe(7);
});
test.each([
[1, 1, 2],
[2, 2, 4],
])("add(%i, %i) is %i", (a, b, sum) => {
expect(a + b).toBe(sum);
});Common Gotchas
`jest.mock` is hoisted above imports
a mock that reads a variable declared below can see a temporal-dead-zone `undefined`. Use `jest.doMock` or factory functions.
Forgotten `await` in an `async` test can pass
always await the work you meant to assert.
Snapshots are tests you must read in review
a huge unexpected snap is a failed review, not a green build.
JSDOM is not a browser
layout, cookies, and some APIs differ. Use Playwright for real browser behaviour.