Get your API key

Lesson 3 of 5

Unit tests with Vitest

Let the AI install Vitest and turn each rule into a test, then read pass and fail output: which test, expected vs received.

9 min Log in to open
One step at a time, like flipping pages.

By the end of this lesson your app will have unit tests for every rule in ACCEPTANCE.md, written by the AI, and you will be able to read a pass or fail result: which test, what was expected, what was received.

You need: your project with ACCEPTANCE.md from Lesson 2, a terminal in the project folder, your coding agent · Time: 9 minutes

  1. Vitest is a free test tool for JavaScript and TypeScript projects. It needs Node.js 22.12 or newer, so check your version first (same command on Windows, macOS and Linux):

    Terminal · macOS / Linux
    node --version

    If it shows v22.12 or higher (for example v24.11.0), you are ready. If not, install the current LTS version from nodejs.org, as in Set up your computer.

    Now let the agent do the setup. Vitest's docs install it with npm install -D vitest; the agent runs that for you:

    Prompt · copy it into your AI agent
    Set up Vitest for unit tests in this project.
    1. Run: npm install -D vitest
    2. In package.json, add the script "test": "vitest run" (run once and exit, not watch mode).
    3. Do not change any app code yet.
    4. Run npm test and paste the full output, even if it says no tests were found.
    Why?

    vitest run runs the tests once and stops. Plain vitest keeps watching for changes, which can leave an agent waiting forever for a command that never ends.

Log in free to read the rest of this lesson

Every lesson is free. A free account unlocks all of them and saves your progress.

Still to come in this lesson:

  1. Turn each criterion into a test
  2. Read a passing run
  3. Read a failing run
  4. Fix the code, not the test
  5. Recap