Files
bun.sh/test/regression/issue/07001.test.ts
Jarred Sumner 4c933f733b Fixes #7001 (#7861)
* Fixes #7001

* One more test

* Use `disturbed`

* [autofix.ci] apply automated fixes

* Fix failing test

* Test is no longer todo!

* Make bodyUsed work too

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-01-11 16:25:26 -08:00

68 lines
1.7 KiB
TypeScript

import { test, expect } from "bun:test";
test("req.body.locked is true after body is consumed", async () => {
const req = new Request("https://example.com/", {
body: "test",
method: "POST",
});
await new Response(req.body).arrayBuffer();
expect(req.body.locked).toBe(true);
});
test("req.bodyUsed is true after body is consumed", async () => {
const req = new Request("https://example.com/", {
body: "test",
method: "POST",
});
await new Response(req.body).arrayBuffer();
expect(req.bodyUsed).toBe(true);
});
test("await fetch(req) throws if req.body is already consumed (arrayBuffer)", async () => {
const req = new Request("https://example.com/", {
body: "test",
method: "POST",
});
await new Response(req.body).arrayBuffer();
expect(() => fetch(req)).toThrow();
expect(req.bodyUsed).toBe(true);
});
test("await fetch(req) throws if req.body is already consumed (text)", async () => {
const req = new Request("https://example.com/", {
body: "test",
method: "POST",
});
await new Response(req.body).text();
expect(() => fetch(req)).toThrow();
expect(req.bodyUsed).toBe(true);
});
test("await fetch(req) throws if req.body is already consumed (stream that has been read)", async () => {
const req = new Request("https://example.com/", {
body: "test",
method: "POST",
});
await req.body.getReader().read();
expect(() => fetch(req)).toThrow();
expect(req.bodyUsed).toBe(true);
});
test("await fetch(req) throws if req.body is already consumed (stream)", async () => {
const req = new Request("https://example.com/", {
body: "test",
method: "POST",
});
req.body.getReader();
expect(() => fetch(req)).toThrow();
expect(req.bodyUsed).toBe(true);
});