Caffeinated Coder
Book an appointment
Lesson 27 · JavaScript beyond the browser

Testing JavaScript

A unit test is code that calls your code with inputs whose answers you know, and checks the result with an assertion. Follow Node.js's built-in test runner through a real discount function: one test passes, the second throws an AssertionError that exposes a bug, the run ends with exit code 1, and a one-line fix turns everything green.

11 min11 steps5 questionsAdvanced
Fig 27 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.