Skip to content

Commit 67f9023

Browse files
Jeniterclaude
andauthored
test: add unit tests for limitNumber (#6844)
Adds a small, focused, additive unit-test file (test/limit-number.test.ts). No existing files are modified or removed. yarn test:ci passes locally. Co-authored-by: ytj-zuel <15623621570> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent f76f144 commit 67f9023

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

test/limit-number.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// app/store/config.ts participates in an import cycle, so a static import can
2+
// hit a temporal-dead-zone error. Load it dynamically in beforeAll instead.
3+
let limitNumber: (x: number, min: number, max: number, def: number) => number;
4+
5+
beforeAll(async () => {
6+
// Warm up the import cycle in a working order before loading the target.
7+
await import("../app/client/api");
8+
({ limitNumber } = await import("../app/store/config"));
9+
});
10+
11+
describe("limitNumber", () => {
12+
test("returns the default value for NaN input", () => {
13+
expect(limitNumber(NaN, 0, 10, 5)).toBe(5);
14+
});
15+
16+
test("clamps values below the minimum up to the minimum", () => {
17+
expect(limitNumber(-3, 0, 10, 5)).toBe(0);
18+
});
19+
20+
test("clamps values above the maximum down to the maximum", () => {
21+
expect(limitNumber(99, 0, 10, 5)).toBe(10);
22+
});
23+
24+
test("returns the value unchanged when it is within range", () => {
25+
expect(limitNumber(7, 0, 10, 5)).toBe(7);
26+
});
27+
28+
test("treats the min and max boundaries as inclusive", () => {
29+
expect(limitNumber(0, 0, 10, 5)).toBe(0);
30+
expect(limitNumber(10, 0, 10, 5)).toBe(10);
31+
});
32+
});

0 commit comments

Comments
 (0)