-
Notifications
You must be signed in to change notification settings - Fork 0
Add comprehensive test coverage across all packages #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { createSearchParams, createURL, parseSearchParams } from "../src/index.js"; | ||
| import { createSearchParams, createURL, getLiteralValue, parseSearchParams } from "../src/index.js"; | ||
|
|
||
| describe("createSearchParams", () => { | ||
| it("should create basic search params", () => { | ||
|
|
@@ -72,6 +72,27 @@ describe("createSearchParams", () => { | |
| "limit=10&search=term&offset=undefined&tagIds%5B%5D=123&tagIds%5B%5D=null&tagIds%5B%5D=321&active=Yes&skip=null", | ||
| ); | ||
| }); | ||
|
|
||
| it("should treat an empty array value as no params", () => { | ||
| const params = createSearchParams({ a: [], b: "test" }); | ||
| expect(params.toString()).toBe("b=test"); | ||
| }); | ||
|
|
||
| it("should treat a two-element array whose first element is not an object as a regular array", () => { | ||
| const params = createSearchParams({ key: ["a", "b"] }); | ||
| expect(params.toString()).toBe("key=a&key=b"); | ||
| }); | ||
|
|
||
| it("should treat a two-element array whose second element is not a string as a regular array", () => { | ||
| const params = createSearchParams({ key: [{ val: "x" }, 42] }); | ||
| expect(params.toString()).toBe("key=%5Bobject+Object%5D&key=42"); | ||
| }); | ||
|
|
||
| it("should serialize as 'undefined' for an Option tuple key that does not exist in the record", () => { | ||
| const options = { eager: "EagerValue" }; | ||
| const params = createSearchParams({ mode: [options, "missing"] }); | ||
| expect(params.get("mode")).toBe("undefined"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("createURL", () => { | ||
|
|
@@ -241,4 +262,33 @@ describe("parseSearchParams", () => { | |
| const result = parseSearchParams(searchParams); | ||
| expect(result).toEqual({ key: ["value1", "value2"] }); | ||
| }); | ||
|
|
||
| it("should skip null/undefined array entries by default", () => { | ||
| const searchParams = new URLSearchParams("ids[]=1&ids[]=null&ids[]=2"); | ||
| const result = parseSearchParams(searchParams); | ||
| expect(result).toEqual({ "ids[]": ["1", null, "2"] }); | ||
| }); | ||
|
Comment on lines
+266
to
+270
|
||
|
|
||
| it("should accumulate more than two values for the same non-[] key into an array", () => { | ||
| const searchParams = new URLSearchParams("tag=a&tag=b&tag=c"); | ||
| const result = parseSearchParams(searchParams); | ||
| expect(result).toEqual({ tag: ["a", "b", "c"] }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getLiteralValue", () => { | ||
| it("should convert the string 'null' to null", () => { | ||
| expect(getLiteralValue("null")).toBeNull(); | ||
| }); | ||
|
|
||
| it("should convert the string 'undefined' to undefined", () => { | ||
| expect(getLiteralValue("undefined")).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("should return any other string unchanged", () => { | ||
| expect(getLiteralValue("hello")).toBe("hello"); | ||
| expect(getLiteralValue("")).toBe(""); | ||
| expect(getLiteralValue("0")).toBe("0"); | ||
| expect(getLiteralValue("false")).toBe("false"); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test name says it "should use default none fallback" when only { separator } is provided, but the expectation is
undefined(i.e., no fallback applied). Rename the test to reflect the actual behavior being asserted, or (if the default is intended to be "N/A" per the function docs) adjust the expectation and implementation accordingly.