Skip to content

Commit f936c6b

Browse files
authored
test(shared): add unit tests for human-readable list formatting
Squashed from PR #98605 after updating branch with current main and passing CI.
1 parent 5ada3ac commit f936c6b

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎src/shared/human-list.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Tests for human-readable list formatting.
2+
import { describe, expect, it } from "vitest";
3+
import { formatHumanList } from "./human-list.js";
4+
5+
describe("formatHumanList", () => {
6+
it("returns empty string for empty array", () => {
7+
expect(formatHumanList([])).toBe("");
8+
});
9+
10+
it("returns the value for single element", () => {
11+
expect(formatHumanList(["apple"])).toBe("apple");
12+
});
13+
14+
it("joins two elements with or", () => {
15+
expect(formatHumanList(["apple", "banana"])).toBe("apple or banana");
16+
});
17+
18+
it("joins three elements with comma and or", () => {
19+
expect(formatHumanList(["apple", "banana", "cherry"])).toBe("apple, banana, or cherry");
20+
});
21+
22+
it("joins four or more elements", () => {
23+
expect(formatHumanList(["a", "b", "c", "d"])).toBe("a, b, c, or d");
24+
});
25+
});

0 commit comments

Comments
 (0)