Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/typescript/test/cost-boundaries.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import assert from "node:assert/strict";
import test from "node:test";
import {CostObservation} from "../src/index.js";

test("cost accepts numeric zero and explicit numeric strings", () => {
for (const amount of [0, "0", 1.25, "1.25"]) {
assert.equal(new CostObservation(amount, "USD", "provider").asEventValue().amount, Number(amount));
}
});

test("cost refuses values that Number would silently coerce", () => {
for (const amount of [true, false, null, [], [1], {}, "", " ", "\t\n"]) {
assert.throws(() => new CostObservation(amount as number, "USD", "provider").asEventValue(), /finite non-negative/);
}
});
Loading