|
| 1 | +import assert from "node:assert"; |
| 2 | +import { URL } from "../URL.mjs"; |
| 3 | + |
| 4 | +describe("SearchParams Tests", () => { |
| 5 | + const url = new URL("https://example.com"); |
| 6 | + |
| 7 | + it("should set and get searchParams number", () => { |
| 8 | + url.searchParams.set("type1", 12345); |
| 9 | + assert.strictEqual(url.search, "?type1=12345"); |
| 10 | + assert.strictEqual(url.href, "https://example.com/?type1=12345"); |
| 11 | + }); |
| 12 | + |
| 13 | + it("should set and get searchParams 0", () => { |
| 14 | + url.searchParams.set("type2", 0); |
| 15 | + assert.strictEqual(url.search, "?type1=12345&type2=0"); |
| 16 | + assert.strictEqual(url.href, "https://example.com/?type1=12345&type2=0"); |
| 17 | + }); |
| 18 | + |
| 19 | + it("should set and get searchParams false", () => { |
| 20 | + url.searchParams.set("type3", false); |
| 21 | + assert.strictEqual(url.search, "?type1=12345&type2=0&type3=false"); |
| 22 | + assert.strictEqual(url.href, "https://example.com/?type1=12345&type2=0&type3=false"); |
| 23 | + }); |
| 24 | + |
| 25 | + it("should set and get searchParams null", () => { |
| 26 | + url.searchParams.set("type4", null); |
| 27 | + assert.strictEqual(url.search, "?type1=12345&type2=0&type3=false&type4=null"); |
| 28 | + assert.strictEqual(url.href, "https://example.com/?type1=12345&type2=0&type3=false&type4=null"); |
| 29 | + }); |
| 30 | + |
| 31 | + it("should set and get searchParams undefined", () => { |
| 32 | + url.searchParams.set("type5"); |
| 33 | + assert.strictEqual(url.search, "?type1=12345&type2=0&type3=false&type4=null&type5"); |
| 34 | + assert.strictEqual(url.href, "https://example.com/?type1=12345&type2=0&type3=false&type4=null&type5"); |
| 35 | + }); |
| 36 | + |
| 37 | +}); |
0 commit comments