What Jest Does
- Zero-config — works out of the box for most JS/TS projects
- Snapshot testing — capture and compare UI output
- Mocking —
jest.fn(),jest.mock(),jest.spyOn() - Code coverage — built-in Istanbul coverage
- Parallel execution — tests run in isolated workers
- Watch mode — re-run changed tests
- Matchers — rich assertion library (
toBe,toEqual,toThrow,toMatchSnapshot) - Timer mocks — fake timers for setTimeout/setInterval
- Async testing — async/await, promises, callbacks
Comparison
| Runner | Speed | TS | ESM | Watch |
|---|---|---|---|---|
| Jest | Medium | Via ts-jest | Experimental | Yes |
| Vitest | Fast | Native | Native | Yes |
| Mocha | Medium | Via ts-node | Yes | Yes |
| Node test runner | Fast | Via tsx | Yes | Yes |
FAQ
Q: Jest vs Vitest? A: Vitest is faster (Vite-powered), native ESM, and TS works without ts-jest. Vitest is recommended for new Vite projects. Jest has a larger ecosystem and more legacy projects.
Q: How to configure TypeScript?
A: Use the ts-jest transformer or @swc/jest (faster). Configure the transform field in jest.config.ts.
Sources
- Docs: https://jestjs.io
- GitHub: https://github.com/jestjs/jest
- License: MIT