Jest là JavaScript testing framework từ Meta, phổ biến nhất trong ecosystem.
- Zero-config với Create React App và Next.js; TypeScript support qua ts-jest hoặc babel-jest.
- Test isolation: mỗi test file chạy trong separate Node.js environment (jsdom hoặc node), global state không leak giữa files.
- Parallel execution: Jest chạy test files song song qua worker pool, isolate failures tốt.
- Snapshot testing: serialize output và so sánh với .snap files — detect unexpected UI changes.
- Mocking system: jest.fn(), jest.mock(), jest.spyOn() — mock modules, timers (jest.useFakeTimers), và globals.
- Code coverage: --coverage flag generate Istanbul reports (statements, branches, functions, lines).
- Watch mode: --watchAll hoặc --watch chỉ re-run tests affected by changes.
- Matchers: toBe (===), toEqual (deep), toMatchObject (partial match), toThrow, toHaveBeenCalledWith, resolves/rejects cho async.
- Setup files: jest.config.js với setupFilesAfterEach để configure Testing Library, mock global APIs.
- Tích hợp với React Testing Library: render, screen, fireEvent, userEvent — test behavior không implementation details.
Jest is a JavaScript testing framework from Meta, the most popular in the ecosystem.
- Zero-config with Create React App and Next.js; TypeScript support via ts-jest or babel-jest.
- Test isolation: each test file runs in a separate Node.js environment (jsdom or node), so global state does not leak between files.
- Parallel execution: Jest runs test files in parallel via a worker pool, isolating failures effectively.
- Snapshot testing: serializes output and compares it with .snap files — detects unexpected UI changes.
- Mocking system: jest.fn(), jest.mock(), jest.spyOn() — mock modules, timers (jest.useFakeTimers), and globals.
- Code coverage: the --coverage flag generates Istanbul reports (statements, branches, functions, lines).
- Watch mode: --watchAll or --watch re-runs only tests affected by changes.
- Matchers: toBe (===), toEqual (deep), toMatchObject (partial match), toThrow, toHaveBeenCalledWith, resolves/rejects for async.
- Setup files: jest.config.js with setupFilesAfterFramework to configure Testing Library and mock global APIs.
- Integration with React Testing Library: render, screen, fireEvent, userEvent — tests behavior, not implementation details.