summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/unit/body_test.ts13
-rw-r--r--cli/tests/unit/fetch_test.ts19
2 files changed, 23 insertions, 9 deletions
diff --git a/cli/tests/unit/body_test.ts b/cli/tests/unit/body_test.ts
index 3b01190a6..ac65a1312 100644
--- a/cli/tests/unit/body_test.ts
+++ b/cli/tests/unit/body_test.ts
@@ -3,9 +3,10 @@ import { unitTest, assertEquals, assert } from "./test_util.ts";
// just a hack to get a body object
// eslint-disable-next-line @typescript-eslint/no-explicit-any
-function buildBody(body: any): Body {
+function buildBody(body: any, headers?: Headers): Body {
const stub = new Request("", {
body: body,
+ headers,
});
return stub as Body;
}
@@ -40,10 +41,7 @@ unitTest(
);
const text = await response.text();
- const body = buildBody(text);
-
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- (body as any).contentType = "multipart/form-data;boundary=boundary";
+ const body = buildBody(text, response.headers);
const formData = await body.formData();
assert(formData.has("field_1"));
@@ -60,10 +58,7 @@ unitTest(
);
const text = await response.text();
- const body = buildBody(text);
-
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- (body as any).contentType = "application/x-www-form-urlencoded";
+ const body = buildBody(text, response.headers);
const formData = await body.formData();
assert(formData.has("field_1"));
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts
index f8ceebf6e..84f2c2822 100644
--- a/cli/tests/unit/fetch_test.ts
+++ b/cli/tests/unit/fetch_test.ts
@@ -851,6 +851,25 @@ unitTest(
}
);
+unitTest(
+ { perms: { net: true } },
+ async function fetchResponseContentLength(): Promise<void> {
+ const body = new Uint8Array(2 ** 16);
+ const headers = new Headers([["content-type", "application/octet-stream"]]);
+ const res = await fetch("http://localhost:4545/echo_server", {
+ body: body,
+ method: "POST",
+ headers,
+ });
+ assertEquals(Number(res.headers.get("content-length")), body.byteLength);
+
+ const blob = await res.blob();
+ // Make sure Body content-type is correctly set
+ assertEquals(blob.type, "application/octet-stream");
+ assertEquals(blob.size, body.byteLength);
+ }
+);
+
unitTest(function fetchResponseConstructorNullBody(): void {
const nullBodyStatus = [204, 205, 304];