diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2020-06-01 01:21:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-31 19:21:14 -0400 |
commit | edeeedf40161dcc4932a33139a7fffa1a73cc142 (patch) | |
tree | b11b63c45c8df035b2a29d5b621ce602f3d5caf2 /cli/tests | |
parent | 08552fc6b9a18c736b6fd3939d8e0b434f5b8302 (diff) |
fix(cli/fetch): set null body for null-body status (#5980)
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/unit/fetch_test.ts | 38 |
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" + ); + } + } + } +); |