Jest Setup and Basic Tests
Install Jest, write describe/it/expect tests, use matchers like toBe and toEqual, and run tests in watch mode during development.
Why Test Frontend Code?
Tests catch regressions when you change code. They document expected behaviour. They give you confidence to refactor. Without tests, every change is a gamble that something else broke.
Installing Jest
For a Vite + React project, use Vitest (a Vite-native Jest-compatible test runner). For other setups, install Jest with babel-jest or ts-jest for TypeScript.
# Vitest (preferred for Vite projects):
npm install -D vitest
# Or Jest with TypeScript:
npm install -D jest @types/jest ts-jest