From edeeedf40161dcc4932a33139a7fffa1a73cc142 Mon Sep 17 00:00:00 2001 From: Marcos Casagrande Date: Mon, 1 Jun 2020 01:21:14 +0200 Subject: fix(cli/fetch): set null body for null-body status (#5980) --- cli/tests/unit/fetch_test.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'cli/tests') 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 { + 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" + ); + } + } + } +); -- cgit v1.2.3