Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.
Merged
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
37 changes: 37 additions & 0 deletions src/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ describe("valid input", () => {
age: "20",
});
});

it("returns empty data and no issues for empty FormData", () => {
const fd = new FormData();

const result = parse(fd);

expect(result.issues).toEqual([]);
expect(result.data).toEqual({});
});

it("stores File values in data", () => {
const fd = new FormData();
const file = new File(["content"], "test.txt", { type: "text/plain" });
fd.append("upload", file);

const result = parse(fd);

assert(result.data !== null);
expect(result.issues).toEqual([]);
expect(result.data["upload"]).toBeInstanceOf(File);
});
});

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

it("reports an issue for each occurrence beyond the first", () => {
const fd = new FormData();
fd.append("a", "1");
fd.append("a", "2");
fd.append("a", "3");

const result = parse(fd);

expect(result.data).toBeNull();
expect(result.issues).toHaveLength(2);
for (const issue of result.issues) {
expect(issue.code).toBe("duplicate_key");
expect(issue.key).toBe("a");
}
});

it("treats bracket notation as opaque keys", () => {
const fd = new FormData();
fd.append("items[]", "1");
Expand Down