Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

Commit e9cf44f

Browse files
authored
test: add missing parse test cases for confirmed specs (#69)
1 parent 7f79fd9 commit e9cf44f

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/parse.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@ describe("valid input", () => {
1515
age: "20",
1616
});
1717
});
18+
19+
it("returns empty data and no issues for empty FormData", () => {
20+
const fd = new FormData();
21+
22+
const result = parse(fd);
23+
24+
expect(result.issues).toEqual([]);
25+
expect(result.data).toEqual({});
26+
});
27+
28+
it("stores File values in data", () => {
29+
const fd = new FormData();
30+
const file = new File(["content"], "test.txt", { type: "text/plain" });
31+
fd.append("upload", file);
32+
33+
const result = parse(fd);
34+
35+
assert(result.data !== null);
36+
expect(result.issues).toEqual([]);
37+
expect(result.data["upload"]).toBeInstanceOf(File);
38+
});
1839
});
1940

2041
describe("duplicate key detection", () => {
@@ -34,6 +55,22 @@ describe("duplicate key detection", () => {
3455
expect(issue.key).toBe("a");
3556
});
3657

58+
it("reports an issue for each occurrence beyond the first", () => {
59+
const fd = new FormData();
60+
fd.append("a", "1");
61+
fd.append("a", "2");
62+
fd.append("a", "3");
63+
64+
const result = parse(fd);
65+
66+
expect(result.data).toBeNull();
67+
expect(result.issues).toHaveLength(2);
68+
for (const issue of result.issues) {
69+
expect(issue.code).toBe("duplicate_key");
70+
expect(issue.key).toBe("a");
71+
}
72+
});
73+
3774
it("treats bracket notation as opaque keys", () => {
3875
const fd = new FormData();
3976
fd.append("items[]", "1");

0 commit comments

Comments
 (0)