TDD (Test‑Driven Development) — write a test first, then minimal code to pass it, then refactor.
Cycle: Red → Green → Refactor.
Benefits: better design, fewer regressions, confidence in changes.
Full Answer
What TDD is
TDD is an iterative process: define behavior via a failing test (Red), add minimal code to pass (Green), then improve the design without changing behavior (Refactor).
TDD cycle
Red: write a test that fails.
Green: write the smallest code to pass.
Refactor: improve structure while tests stay green.
Mini example:
// Red: failing test — function missing or behavior not implementedexpect(sum(1, 2)).toBe(3);// Green: minimal implementationfunction sum(a, b) { return a + b; }