Programming foundations

Stage 6 · Lesson 6 of 8

Tests on the core logic

Build and ship your first projects

Test the that hold your project's rules, not the file or network code around them. is a common choice for unit tests. Install it with npm install -D vitest, name files like budget.test.js, and write tests such as test("totals a month", () => { expect(monthlyTotal(entries)).toBe(42.5); }).

also ships a built-in runner, node --test with node:test and node:assert, if you want no at all. Cover such as an empty array, one entry and invalid input. Use expect(() => parseAmount("abc")).toThrow() for rejected input, and toBeCloseTo for decimals.

Put the runner in the test script so npm test works. When you find a bug, write the failing test first.

A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with· follow one of these

  • GitHub repoFree
    Project Based Learning

    Community maintained · Beginner

    Follow one guided build in your language, then build your own without a guide

  • BookFree
    Eloquent JavaScript

    Marijn Haverbeke · Intermediate

    Free: the project chapters (a robot, a programming language, a pixel editor) show real structure

Keep handy

  • Free APIs that give a small project real data to work with

Also worth your time

Mark this stage as not done?