Skip to content

Commit

Permalink
test: SearchParams
Browse files Browse the repository at this point in the history
Create SearchParams.test.js
  • Loading branch information
VirgilClyne committed Nov 24, 2024
1 parent c1c1091 commit 435f4e7
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/SearchParams.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import assert from "node:assert";
import { URL } from "../URL.mjs";

describe("SearchParams Tests", () => {
const url = new URL("https://example.com");

it("should set and get searchParams number", () => {
url.searchParams.set("type1", 12345);
assert.strictEqual(url.search, "?type1=12345");
assert.strictEqual(url.href, "https://example.com/?type1=12345");
});

it("should set and get searchParams 0", () => {
url.searchParams.set("type2", 0);
assert.strictEqual(url.search, "?type1=12345&type2=0");
assert.strictEqual(url.href, "https://example.com/?type1=12345&type2=0");
});

it("should set and get searchParams false", () => {
url.searchParams.set("type3", false);
assert.strictEqual(url.search, "?type1=12345&type2=0&type3=false");
assert.strictEqual(url.href, "https://example.com/?type1=12345&type2=0&type3=false");
});

it("should set and get searchParams null", () => {
url.searchParams.set("type4", null);
assert.strictEqual(url.search, "?type1=12345&type2=0&type3=false&type4=null");
assert.strictEqual(url.href, "https://example.com/?type1=12345&type2=0&type3=false&type4=null");
});

it("should set and get searchParams undefined", () => {
url.searchParams.set("type5");
assert.strictEqual(url.search, "?type1=12345&type2=0&type3=false&type4=null&type5");
assert.strictEqual(url.href, "https://example.com/?type1=12345&type2=0&type3=false&type4=null&type5");
});

});

0 comments on commit 435f4e7

Please sign in to comment.