diff options
Diffstat (limited to 'test/js/web/fetch/fetch.test.ts')
-rw-r--r-- | test/js/web/fetch/fetch.test.ts | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/test/js/web/fetch/fetch.test.ts b/test/js/web/fetch/fetch.test.ts index 065506fad..1f2345f85 100644 --- a/test/js/web/fetch/fetch.test.ts +++ b/test/js/web/fetch/fetch.test.ts @@ -718,7 +718,8 @@ describe("Blob", () => { it(`${Constructor.name} arrayBuffer() with ${TypedArray.name}${withGC ? " with gc" : ""}`, async () => { const data = new TypedArray(sample); if (withGC) gc(); - const input = Constructor === Blob ? [data] : Constructor === Request ? { body: data } : data; + const input = + Constructor === Blob ? [data] : Constructor === Request ? { body: data, url: "http://example.com" } : data; if (withGC) gc(); const blob = new Constructor(input); if (withGC) gc(); @@ -1098,3 +1099,30 @@ it("body nullable", async () => { expect(req.body).not.toBeNull(); } }); + +it("Request({}) throws", async () => { + expect(() => new Request({})).toThrow(); +}); + +it("Request({toString() { throw 'wat'; } }) throws", async () => { + expect( + () => + new Request({ + toString() { + throw "wat"; + }, + }), + ).toThrow("wat"); +}); + +it("should not be able to parse json from empty body", () => { + expect(async () => await new Response().json()).toThrow(SyntaxError); + expect(async () => await new Request("http://example.com/").json()).toThrow(SyntaxError); +}); + +it("#874", () => { + expect(new Request(new Request("https://example.com"), {}).url).toBe("https://example.com"); + expect(new Request(new Request("https://example.com")).url).toBe("https://example.com"); + // @ts-expect-error + expect(new Request({ url: "https://example.com" }).url).toBe("https://example.com"); +}); |