From 5a23d176208bb38483b65b9420b18c8597fabfef Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 19 Mar 2023 14:08:20 -0700 Subject: Several bug fixes (#2427) * Fix test * Fix segfault when unexpected type is passed in `expect().toThrow` * Fix issues with request constructor * Don't bother cloning headers when its empty * woops * more tests * fix incorrect test * Make the fetch error messages better * Update response.zig * Fix test that failed on macOS * Fix test * Remove extra hash table lookups * Support running dummy registry directly cc @alexlamsl * Update test * Update test * fixup * Workaround crash in test runner * Fixup test * Fixup test * Update os.test.js --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> --- test/js/web/fetch/fetch.test.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'test/js/web/fetch/fetch.test.ts') 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"); +}); -- cgit v1.2.3