StoicBuilder
Later missionMission 27: First day on the Harbor teamYou can practise it now. It counts once you reach mission 27, after “Your first feature”.Back to HQ
Exit lesson
Writing a unit testProLesson 22 of 45, about 8 min
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
0 XP

The app: Bench, a test runner

Benchharbor / billingVitest
proration.test.js

Not run yet.

  • charges something mid-month

The code, the tests and the test run

billing/proration.js the codeprorate
1// Harbor bills on the 1st. A team that upgrades mid-month pays2// for the days left, from the upgrade day to the end of the month.3export function prorate(priceCents, day, daysInMonth) {45 return (priceCents * daysLeft) / daysInMonth;6}
billing/proration.test.js the tests1 test
1import { expect, test } from "vitest";2import { prorate } from "./proration";3 4test("charges something mid-month", () => {56});
Terminal npx vitest runnot run

Nothing has run yet. Press Run tests.

The MagisterThis is Bench, a test runner. On the right: prorate, which Harbor uses when a team upgrades mid-month, and the one test anyone wrote for it. A unit test calls one function with inputs you choose and checks what comes back. Press Run tests, then tap what this test checks.

Step 1 of 8Run the test that is already there
  • Run the tests
  • Tap the line that checks the result

You’re not signed in, so this lesson won’t be saved to your path. Sign in free to keep your XP.