Jest and Vitest
You wrote some JavaScript, it works on your machine, and now someone wants tests. You open the docs and drown in describe, it, beforeEach, jest.fn(), toHaveBeenCalledWith, snapshots, and two tools that look nearly identical. This guide cuts through it. You will learn one mental model that covers both Jest and Vitest, write tests you trust, and know exactly when to reach for which.
How to read this
Read it in order the first time. Phase 1 gives you the shape of a test and why these tools exist. Phase 2 is the daily work: matchers, mocks, async, timers - the stuff you'll use every hour. Phase 3 is where tests go wrong: snapshot rot, flaky timers, mock leakage, and choosing between the two runners. If you've never written a unit test, read Your First Unit Test first; this guide assumes you know what an assertion is.