diff options
| author | Marcos Casagrande <marcoscvp90@gmail.com> | 2020-07-06 03:37:18 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-05 21:37:18 -0400 |
| commit | 3b4260dc54237070e28f31e6253f3fa125153638 (patch) | |
| tree | cee70005c11e9e03315ae1c8eb80fd6d64c0908f /cli/tests/unit | |
| parent | 5b09e721d3a390bbe79ac0403ab0670faeb12823 (diff) | |
fix(cli/fetch): response constructor default properties (#6650)
Diffstat (limited to 'cli/tests/unit')
| -rw-r--r-- | cli/tests/unit/fetch_test.ts | 74 |
1 files changed, 41 insertions, 33 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index 1dab8f7f9..f8ceebf6e 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -851,42 +851,50 @@ unitTest( } ); -unitTest( - { perms: { net: true } }, - function fetchResponseConstructorNullBody(): void { - const nullBodyStatus = [204, 205, 304]; +unitTest(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" - ); - } + 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" + ); } } -); +}); -unitTest( - { perms: { net: true } }, - function fetchResponseConstructorInvalidStatus(): void { - const invalidStatus = [101, 600, 199]; - - for (const status of invalidStatus) { - try { - new Response("deno", { status }); - fail("Invalid status"); - } catch (e) { - assert(e instanceof RangeError); - assertEquals( - e.message, - `The status provided (${status}) is outside the range [200, 599]` - ); - } +unitTest(function fetchResponseConstructorInvalidStatus(): void { + const invalidStatus = [101, 600, 199, null, "", NaN]; + + for (const status of invalidStatus) { + try { + // deno-lint-ignore ban-ts-comment + // @ts-ignore + new Response("deno", { status }); + fail(`Invalid status: ${status}`); + } catch (e) { + assert(e instanceof RangeError); + assertEquals( + e.message, + `The status provided (${status}) is outside the range [200, 599]` + ); } } -); +}); + +unitTest(function fetchResponseEmptyConstructor(): void { + const response = new Response(); + assertEquals(response.status, 200); + assertEquals(response.body, null); + assertEquals(response.type, "default"); + assertEquals(response.url, ""); + assertEquals(response.redirected, false); + assertEquals(response.ok, true); + assertEquals(response.bodyUsed, false); + assertEquals([...response.headers], []); +}); |
