diff options
Diffstat (limited to 'test/js/web/fetch')
-rw-r--r-- | test/js/web/fetch/headers.test.ts | 41 |
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); |