summaryrefslogtreecommitdiff
path: root/cli/tests/unit/fetch_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/unit/fetch_test.ts')
-rw-r--r--cli/tests/unit/fetch_test.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts
index 5fd1cc469..c1dde92a9 100644
--- a/cli/tests/unit/fetch_test.ts
+++ b/cli/tests/unit/fetch_test.ts
@@ -713,3 +713,41 @@ unitTest(
await res.body.cancel();
}
);
+
+unitTest(
+ { perms: { net: true } },
+ async function fetchNullBodyStatus(): Promise<void> {
+ const nullBodyStatus = [204, 205, 304];
+
+ for (const status of nullBodyStatus) {
+ const headers = new Headers([["x-status", String(status)]]);
+ const res = await fetch("http://localhost:4545/cli/tests/echo_server", {
+ body: "deno",
+ method: "POST",
+ headers,
+ });
+ assertEquals(res.body, null);
+ assertEquals(res.status, status);
+ }
+ }
+);
+
+unitTest(
+ { perms: { net: true } },
+ function fetchResponseConstructorNullBody(): void {
+ const nullBodyStatus = [204, 205, 304];
+
+ for (const status of nullBodyStatus) {
+ try {
+ new Response("deno", { status });
+ fail("Response with null body status cannot have body");
+ } catch (e) {
+ assert(e instanceof TypeError);
+ assertEquals(
+ e.message,
+ "Response with null body status cannot have body"
+ );
+ }
+ }
+ }
+);