Add Focused Financial Tests
The most valuable automated tests in this project are the rules that can quietly change while the UI still appears normal: date validation, money parsing, totals, category shares, and averages.
The project uses Node’s built-in test runner, so there is no new testing framework to learn.
Open the root package.json and make sure the test script exists:
{
"scripts": {
"test": "node --test"
}
}
Then open tests/finance.test.js and import the pure helpers you want to verify. A test has three basic parts: arrange an input, call the function, and assert the expected result.
For example:
import test from "node:test";
import assert from "node:assert/strict";
import { parseAmountToCents } from "../client/src/lib/finance.js";
test("parses an amount into cents", () => {
assert.equal(parseAmountToCents("84.50"), 8450);
});
The import points directly to the financial helper because the helper has no React or browser dependency. That is exactly why we centralized the rules earlier.
Add tests for the important edge cases:
2026-02-29 is invalid
2024-02-29 is valid
84.50 becomes 8450
84.567 is rejected
zero expenses produce zero category shares
average monthly spending includes months with zero expenses
income contributes to income totals, not expense totals
Keep the tests small. A test should tell you what rule failed without making you read a whole component to understand the setup.
Test it
Run:
npm test
Read the output rather than only looking for a green process exit. Each test name should tell you which financial rule is being protected.
Checkpoint
The project’s most important calculations can now be verified without opening a browser, so a future UI change is less likely to silently break financial behavior.