StoicBuilder

HandbookIII the CastraBasic tests

IIIthe Castra, Stay in control

Basic tests

1 min readUpdated 28 November

In plain words

A test is a small piece of code that runs part of your app and checks the result, so you learn when a change breaks something.

Where you see it

You ask the agent to fix QuickBite's discount codes and, without mentioning it, it changes how delivery is added. A test that expects 2 pizzas at 9.50 plus 3.00 delivery to cost 22.00 turns red, and you know before your customers do.

lib/orderTotal.test.tsterminal
import { expect, test } from "vitest";import { orderTotal } from "./orderTotal"; test("adds delivery to the item total", () => { const items = [{ price: 9.5, quantity: 2 }]; expect(orderTotal(items, 3)).toBe(22);});
Run it with npx vitest after every change. Green means this still works.

What goes wrong

  1. Letting the agent edit the test until it passes

    When a test fails, the agent may change what the test expects instead of fixing the code. In the diff, a changed expected value deserves a question.

  2. Tests that check nothing

    toBeDefined() passes for the wrong total too. Check the actual value you care about.

    expect(orderTotal(items, 3)).toBeDefined();
  3. Tests nobody runs

    Tests only help if they run on every change. Ask the agent to run them before it says it's done, or set them to run on every push.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Write a few Vitest tests for the code that handles money, permissions and saving data, using exact expected values. Run them after every change, and if one fails, fix the code rather than the test unless you ask me first.

Quick check

Sign in to earn +10 XP for it

A test fails after the agent's change. The agent edits the test's expected value and now everything passes. What next?

Got a prompt that touches basic tests?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.