test(shared): add unit tests for numeric coercion helper (#98663)

* test(shared): add unit tests for numeric coercion helper

* test(shared): cover numeric coercion boundaries

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
dwc1997
2026-07-18 14:17:34 +08:00
committed by GitHub
parent e5ac755681
commit ec3eb573bf

View File

@@ -0,0 +1,18 @@
import { describe, expect, it } from "vitest";
import { resolveNonNegativeNumber } from "./number-coercion.js";
describe("resolveNonNegativeNumber", () => {
it.each([0, -0, 1.25, Number.MIN_VALUE, Number.MAX_VALUE])(
"preserves finite non-negative value %s",
(value) => {
expect(resolveNonNegativeNumber(value)).toBe(value);
},
);
it.each([-1, -0.1, Number.NaN, Infinity, -Infinity, null, undefined])(
"rejects invalid value %s",
(value) => {
expect(resolveNonNegativeNumber(value)).toBeUndefined();
},
);
});