From c1fdb30394ab336ec2e004d563be40180e218b0d Mon Sep 17 00:00:00 2001 From: Yosi Pramajaya Date: Sat, 26 Dec 2020 20:06:00 +0700 Subject: fix: fetch bad URL will not panic (#8884) --- cli/tests/unit/fetch_test.ts | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'cli/tests/unit/fetch_test.ts') diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index 359a24e95..2355d0813 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -27,12 +27,37 @@ unitTest( async (): Promise => { await fetch("http://localhost:4000"); }, - Deno.errors.Http, + TypeError, "error trying to connect", ); }, ); +unitTest( + { perms: { net: true } }, + async function fetchDnsError(): Promise { + await assertThrowsAsync( + async (): Promise => { + await fetch("http://nil/"); + }, + TypeError, + "error trying to connect", + ); + }, +); + +unitTest( + { perms: { net: true } }, + async function fetchInvalidUriError(): Promise { + await assertThrowsAsync( + async (): Promise => { + await fetch("http:///"); + }, + URIError, + ); + }, +); + unitTest({ perms: { net: true } }, async function fetchJsonSuccess(): Promise< void > { @@ -199,9 +224,12 @@ unitTest({ perms: { net: true } }, async function responseClone(): Promise< unitTest({ perms: { net: true } }, async function fetchEmptyInvalid(): Promise< void > { - await assertThrowsAsync(async () => { - await fetch(""); - }, URIError); + await assertThrowsAsync( + async () => { + await fetch(""); + }, + URIError, + ); }); unitTest( -- cgit v1.2.3