Files
fieldwork/tests/format.test.js
T
jzzliu eb101c3e05 Add dependency-free browser test suite and README
49 tests run in headless Chrome via tests/run.sh: unit tests for the pure
modules plus integration tests that drive the real page in an iframe
(filtering, URL state, bag, limits, cross-tab sync, checkout, dialogs,
accessibility and overflow checks).
2026-11-07 21:18:38 -07:00

27 lines
782 B
JavaScript

import { money, plural } from "../dist/js/format.js";
import { equal, test } from "./harness.js";
test("format: whole-dollar amounts drop the cents", () => {
equal(money(8600), "$86");
equal(money(0), "$0");
});
test("format: other amounts show exact cents", () => {
equal(money(8650), "$86.50");
equal(money(99), "$0.99");
equal(money(123456), "$1,234.56");
});
test("format: integer cents sum exactly (no float drift)", () => {
// 0.1 + 0.2 style errors cannot happen with integer cents
equal(money(10 + 20), "$0.30");
equal(money(3 * 2400 + 8600), "$158");
});
test("format: plural", () => {
equal(plural(1, "item"), "1 item");
equal(plural(0, "item"), "0 items");
equal(plural(3, "item"), "3 items");
equal(plural(2, "box", "boxes"), "2 boxes");
});