aboutsummaryrefslogtreecommitdiff
path: root/test/js/web/fetch
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-05-26 16:28:09 -0700
committerGravatar GitHub <noreply@github.com> 2023-05-26 16:28:09 -0700
commit3a0735e16470cde796c1420f4db982af61bdab9c (patch)
treefd16595c122f085c5f18465f6db130e7f219dfbf /test/js/web/fetch
parent42125b43513a76e3e18b2b76ecc4323b1d8e1b3a (diff)
downloadbun-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/fetch')
-rw-r--r--test/js/web/fetch/headers.test.ts41
1 files changed, 39 insertions, 2 deletions
diff --git a/test/js/web/fetch/headers.test.ts b/test/js/web/fetch/headers.test.ts
index 48cd3ad35..8ae17c11e 100644
--- a/test/js/web/fetch/headers.test.ts
+++ b/test/js/web/fetch/headers.test.ts
@@ -412,10 +412,46 @@ describe("Headers", () => {
]);
});
});
- describe("toJSON()", () => {
+ describe("Bun.inspect()", () => {
const it = "toJSON" in new Headers() ? test : test.skip;
it("can convert to json when empty", () => {
const headers = new Headers();
+ expect(Bun.inspect(headers)).toStrictEqual(`Headers {}`);
+ });
+ it("can convert to json", () => {
+ const headers = new Headers({
+ "cache-control": "public, immutable",
+ });
+ expect(Bun.inspect(headers)).toStrictEqual(
+ "Headers {" + "\n " + `"cache-control": "public, immutable"` + "\n" + "}",
+ );
+ });
+ it("can convert to json normalized", () => {
+ const headers = new Headers({
+ "user-agent": "bun",
+ "X-Custom-Header": "1",
+ "cache-control": "public, immutable",
+ });
+ expect(Bun.inspect(headers)).toStrictEqual(
+ "Headers " +
+ JSON.stringify(
+ {
+ "user-agent": "bun",
+ "cache-control": "public, immutable",
+ "x-custom-header": "1",
+ },
+ null,
+ 2,
+ ),
+ );
+ });
+ });
+ describe("toJSON()", () => {
+ // @ts-ignore
+ const it = new Headers()?.toJSON ? test : test.skip;
+
+ it("can convert to json when empty", () => {
+ const headers = new Headers();
expect(headers.toJSON()).toStrictEqual({});
});
it("can convert to json", () => {
@@ -440,7 +476,8 @@ describe("Headers", () => {
});
});
describe("count", () => {
- const it = "count" in new Headers() ? test : test.skip;
+ // @ts-ignore
+ const it = typeof new Headers()?.count !== "undefined" ? test : test.skip;
it("can count headers when empty", () => {
const headers = new Headers();
expect(headers.count).toBe(0);