In plain words
A unit test runs one small piece of code, usually a single function, with inputs you choose and checks the exact result, without a database, network or browser.
Where you see it
Harbor's prorate function works out what a team owes when it moves from Starter to Pro halfway through a month. Next to it sits prorate.test.ts, which calls it with a dozen dates and amounts, and Vitest runs them all in under a second on every save.
What goes wrong
- Testing the code against itself
If the agent works out the expected value with the same formula the function uses, the test passes whether the formula is right or wrong. Expected values should come from a worked example on paper.
expect(total(items)).toBe(items.reduce((sum, i) => sum + i.price, 0)); - Only testing the ordinary case
Most billing bugs live at the edges: the first or last day of a period, a downgrade, a free plan, February. Add a test for each edge you can name.
- Testing how it works instead of what it returns
A test that checks which helper got called breaks every time the code is reorganised, even when the answer is still right. Check the output, not the internals.
What to tell your agent
Quick check
Sign in to earn +10 XP for itYour agent's test for Harbor's invoice total computes the expected value with the same reduce call the function uses. Why is that a problem?