summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/rt/24_body.js2
-rw-r--r--cli/tests/unit/fetch_test.ts10
2 files changed, 11 insertions, 1 deletions
diff --git a/cli/rt/24_body.js b/cli/rt/24_body.js
index a3348907b..f755e2bad 100644
--- a/cli/rt/24_body.js
+++ b/cli/rt/24_body.js
@@ -85,7 +85,7 @@
const enc = new TextEncoder();
return enc.encode(bodySource.toString()).buffer;
} else if (!bodySource) {
- return null;
+ return new ArrayBuffer(0);
}
throw new Error(
`Body type not implemented: ${bodySource.constructor.name}`,
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts
index 012ce7b34..4bdb54d9e 100644
--- a/cli/tests/unit/fetch_test.ts
+++ b/cli/tests/unit/fetch_test.ts
@@ -738,6 +738,16 @@ unitTest(function responseRedirect(): void {
assertEquals(redir.type, "default");
});
+unitTest(async function responseWithoutBody(): Promise<void> {
+ const response = new Response();
+ assertEquals(await response.arrayBuffer(), new ArrayBuffer(0));
+ assertEquals(await response.blob(), new Blob([]));
+ assertEquals(await response.text(), "");
+ await assertThrowsAsync(async () => {
+ await response.json();
+ });
+});
+
unitTest({ perms: { net: true } }, async function fetchBodyReadTwice(): Promise<
void
> {