Testing Frameworks

An automated test is code that calls your code and fails loudly when the result is wrong. Once a bug has a test it cannot return unnoticed: CI runs the suite on every push (Version Control Essentials), and a refactoring that breaks the cart turns a line red instead of reaching a customer.

Front-end tests come in three sizes. Unit tests call one function or component in isolation and finish in milliseconds. Integration tests render several pieces together, often against a simulated DOM. End-to-end (E2E) tests start the real site, drive a real browser and click through it as a user would; they catch the most realistic failures but run slowest and break most often. The usual advice is many small tests at the bottom and a few critical user journeys at the top.

The testing pyramid: speed and number of tests fall as realism rises
The testing pyramid: speed and number of tests fall as realism rises

A testing setup does four jobs: a runner finds and runs test files, an assertion library provides expect(x).toBe(y), test doubles (mocks, spies, fake timers) replace real dependencies, and an environment supplies Node.js 2,131 , a simulated DOM or a real browser. Jest 62,362 and Vitest 102,989 do all four; Mocha 120,373 is only a runner, which is why it is installed alongside Chai 206,458 .

Subsections