diff options
author | Casper Beyer <caspervonb@pm.me> | 2020-06-25 06:57:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-25 00:57:08 +0200 |
commit | 87f8f99c49e62c06f85bb453a7c12b32634c3bef (patch) | |
tree | e8f966f981a9f825ca1f22fe8d39642c448a9c62 /cli/tests/unit/read_dir_test.ts | |
parent | 6bbe52fba33e440e113bca423b5eae0d1f320c49 (diff) |
refactor(cli/tests/unit) to use assertThrows (#6459)
Diffstat (limited to 'cli/tests/unit/read_dir_test.ts')
-rw-r--r-- | cli/tests/unit/read_dir_test.ts | 48 |
1 files changed, 12 insertions, 36 deletions
diff --git a/cli/tests/unit/read_dir_test.ts b/cli/tests/unit/read_dir_test.ts index d9a5244c7..de4b217bf 100644 --- a/cli/tests/unit/read_dir_test.ts +++ b/cli/tests/unit/read_dir_test.ts @@ -3,6 +3,8 @@ import { unitTest, assert, assertEquals, + assertThrows, + assertThrowsAsync, pathToAbsoluteFileUrl, } from "./test_util.ts"; @@ -30,42 +32,21 @@ unitTest({ perms: { read: true } }, function readDirSyncWithUrl(): void { }); unitTest({ perms: { read: false } }, function readDirSyncPerm(): void { - let caughtError = false; - try { + assertThrows(() => { Deno.readDirSync("tests/"); - } catch (e) { - caughtError = true; - assert(e instanceof Deno.errors.PermissionDenied); - } - assert(caughtError); + }, Deno.errors.PermissionDenied); }); unitTest({ perms: { read: true } }, function readDirSyncNotDir(): void { - let caughtError = false; - let src; - - try { - src = Deno.readDirSync("cli/tests/fixture.json"); - } catch (err) { - caughtError = true; - assert(err instanceof Error); - } - assert(caughtError); - assertEquals(src, undefined); + assertThrows(() => { + Deno.readDirSync("cli/tests/fixture.json"); + }, Error); }); unitTest({ perms: { read: true } }, function readDirSyncNotFound(): void { - let caughtError = false; - let src; - - try { - src = Deno.readDirSync("bad_dir_name"); - } catch (err) { - caughtError = true; - assert(err instanceof Deno.errors.NotFound); - } - assert(caughtError); - assertEquals(src, undefined); + assertThrows(() => { + Deno.readDirSync("bad_dir_name"); + }, Deno.errors.NotFound); }); unitTest({ perms: { read: true } }, async function readDirSuccess(): Promise< @@ -93,12 +74,7 @@ unitTest({ perms: { read: true } }, async function readDirWithUrl(): Promise< unitTest({ perms: { read: false } }, async function readDirPerm(): Promise< void > { - let caughtError = false; - try { + await assertThrowsAsync(async () => { await Deno.readDir("tests/")[Symbol.asyncIterator]().next(); - } catch (e) { - caughtError = true; - assert(e instanceof Deno.errors.PermissionDenied); - } - assert(caughtError); + }, Deno.errors.PermissionDenied); }); |