intermediate
Vitest and Jest
Run fast unit and integration tests with watch mode, fake timers, module mocking, snapshots where useful, and TypeScript-aware setup.
Jest and Vitest are JS/TS test runners with describe/it, matchers, mocking, snapshots, and watch mode. Vitest leverages Vite's transform pipeline for faster cold starts and native ESM; Jest has the broader legacy ecosystem and mature snapshot tooling.
Use `vi.useFakeTimers()` / `jest.useFakeTimers()` for time-dependent code, `vi.mock` for module boundaries, and setup files for global matchers like Testing Library extensions.
On interviews: compare Vitest versus Jest for a Vite monorepo and mention how you structure setup, globals, and TypeScript paths.
Common pitfalls: leaking mocks between tests, snapshot churn without review, and running integration tests with over-mocked modules.
The trade-off is Vitest speed versus Jest plugin maturity in mixed legacy repos.
Checklist:
- Reset mocks and timers in `afterEach`.
- Keep setup files minimal and explicit.
- Choose runner based on bundler and ESM needs.