diff options
| author | 2023-05-26 16:28:09 -0700 | |
|---|---|---|
| committer | 2023-05-26 16:28:09 -0700 | |
| commit | 3a0735e16470cde796c1420f4db982af61bdab9c (patch) | |
| tree | fd16595c122f085c5f18465f6db130e7f219dfbf /test/js/web/html/URLSearchParams.test.ts | |
| parent | 42125b43513a76e3e18b2b76ecc4323b1d8e1b3a (diff) | |
| download | bun-3a0735e16470cde796c1420f4db982af61bdab9c.tar.gz bun-3a0735e16470cde796c1420f4db982af61bdab9c.tar.zst bun-3a0735e16470cde796c1420f4db982af61bdab9c.zip | |
Pretty formatter for `Headers` & `URLSearchParams` (#3081)
* Pretty formatter for `Headers` & `URLSearchParams`
* cleanup
* console.log on Headers, FormData, URLSearchParams will always quote the keys now
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'test/js/web/html/URLSearchParams.test.ts')
| -rw-r--r-- | test/js/web/html/URLSearchParams.test.ts | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/js/web/html/URLSearchParams.test.ts b/test/js/web/html/URLSearchParams.test.ts new file mode 100644 index 000000000..028590971 --- /dev/null +++ b/test/js/web/html/URLSearchParams.test.ts @@ -0,0 +1,63 @@ +import { describe, it, expect } from "bun:test"; + +describe("URLSearchParams", () => { + describe("non-standard extensions", () => { + it("should support .length", () => { + const params = new URLSearchParams(); + params.append("foo", "bar"); + params.append("foo", "boop"); + params.append("bar", "baz"); + expect(params.length).toBe(3); + params.delete("foo"); + expect(params.length).toBe(1); + params.append("foo", "bar"); + expect(params.length).toBe(2); + params.delete("foo"); + params.delete("foo"); + expect(params.length).toBe(1); + params.delete("bar"); + expect(params.length).toBe(0); + }); + + it("should support .toJSON", () => { + const params = new URLSearchParams(); + params.append("foo", "bar"); + params.append("foo", "boop"); + params.append("bar", "baz"); + // @ts-ignore + expect(params.toJSON()).toEqual({ + foo: ["bar", "boop"], + bar: "baz", + }); + expect(JSON.parse(JSON.stringify(params))).toEqual({ + foo: ["bar", "boop"], + bar: "baz", + }); + expect(Bun.inspect(params)).toBe( + "URLSearchParams {" + "\n" + ' foo: [ "bar", "boop" ],' + "\n" + ' bar: "baz"' + "\n" + "}", + ); + params.delete("foo"); + // @ts-ignore + expect(params.toJSON()).toEqual({ + bar: "baz", + }); + params.append("foo", "bar"); + // @ts-ignore + expect(params.toJSON()).toEqual({ + foo: "bar", + bar: "baz", + }); + params.delete("foo"); + params.delete("foo"); + // @ts-ignore + expect(params.toJSON()).toEqual({ + bar: "baz", + }); + params.delete("bar"); + // @ts-ignore + expect(params.toJSON()).toEqual({}); + + expect(JSON.stringify(params)).toBe("{}"); + }); + }); +}); |
