aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/fetch.test.js
diff options
context:
space:
mode:
authorGravatar Eric Zhang <ekzhang1@gmail.com> 2023-02-14 18:43:18 -0500
committerGravatar GitHub <noreply@github.com> 2023-02-14 15:43:18 -0800
commit6e1a52691a370058e97ddb84c8f7c49e5bbf1e7e (patch)
tree22c61cce8c78027edf549203deb41d2abdd9a5b4 /test/bun.js/fetch.test.js
parentef75cd46588ab54e14ad286000ef0357a9b76298 (diff)
downloadbun-6e1a52691a370058e97ddb84c8f7c49e5bbf1e7e.tar.gz
bun-6e1a52691a370058e97ddb84c8f7c49e5bbf1e7e.tar.zst
bun-6e1a52691a370058e97ddb84c8f7c49e5bbf1e7e.zip
Reject with error when invalid fetch() body (#2047)
* Reject with error when invalid fetch() body Resolves #2014 * Make sure the test actually throws an exception * Update fetch error paths to return TypeErrors
Diffstat (limited to 'test/bun.js/fetch.test.js')
-rw-r--r--test/bun.js/fetch.test.js27
1 files changed, 26 insertions, 1 deletions
diff --git a/test/bun.js/fetch.test.js b/test/bun.js/fetch.test.js
index b41e5f129..8758e4889 100644
--- a/test/bun.js/fetch.test.js
+++ b/test/bun.js/fetch.test.js
@@ -172,6 +172,31 @@ describe("fetch", () => {
expect(response.redirected).toBe(true);
server.stop();
});
+
+ it("provide body", async () => {
+ const server = Bun.serve({
+ port: 4084,
+ fetch(req) {
+ return new Response(req.body);
+ },
+ });
+
+ // POST with body
+ const url = `http://${server.hostname}:${server.port}`;
+ const response = await fetch(url, { method: "POST", body: "buntastic" });
+ expect(response.status).toBe(200);
+ expect(await response.text()).toBe("buntastic");
+
+ // GET cannot have body
+ try {
+ await fetch(url, { body: "buntastic" });
+ expect(false).toBe(true);
+ } catch (exception) {
+ expect(exception instanceof TypeError).toBe(true);
+ }
+
+ server.stop();
+ });
});
it("simultaneous HTTPS fetch", async () => {
@@ -630,7 +655,7 @@ describe("Response", () => {
await body.json();
expect(false).toBe(true);
} catch (exception) {
- expect(exception instanceof SyntaxError);
+ expect(exception instanceof SyntaxError).toBe(true);
}
});