diff options
author | 2023-03-19 14:08:20 -0700 | |
---|---|---|
committer | 2023-03-19 14:08:20 -0700 | |
commit | 5a23d176208bb38483b65b9420b18c8597fabfef (patch) | |
tree | f163dc03fdc75b7827ee7f51e17355a9cc82329f /test/js/web/fetch/fetch.test.ts | |
parent | 8f02ef829474cbd5453ffcb6485d40f93424ad26 (diff) | |
download | bun-5a23d176208bb38483b65b9420b18c8597fabfef.tar.gz bun-5a23d176208bb38483b65b9420b18c8597fabfef.tar.zst bun-5a23d176208bb38483b65b9420b18c8597fabfef.zip |
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>
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"); +}); |