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_text_file_test.ts | |
parent | 6bbe52fba33e440e113bca423b5eae0d1f320c49 (diff) |
refactor(cli/tests/unit) to use assertThrows (#6459)
Diffstat (limited to 'cli/tests/unit/read_text_file_test.ts')
-rw-r--r-- | cli/tests/unit/read_text_file_test.ts | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/cli/tests/unit/read_text_file_test.ts b/cli/tests/unit/read_text_file_test.ts index 0f1759c54..4222da5a9 100644 --- a/cli/tests/unit/read_text_file_test.ts +++ b/cli/tests/unit/read_text_file_test.ts @@ -2,6 +2,8 @@ import { unitTest, assert, assertEquals, + assertThrows, + assertThrowsAsync, pathToAbsoluteFileUrl, } from "./test_util.ts"; @@ -22,27 +24,15 @@ unitTest({ perms: { read: true } }, function readTextFileSyncByUrl(): void { }); unitTest({ perms: { read: false } }, function readTextFileSyncPerm(): void { - let caughtError = false; - try { + assertThrows(() => { Deno.readTextFileSync("cli/tests/fixture.json"); - } catch (e) { - caughtError = true; - assert(e instanceof Deno.errors.PermissionDenied); - } - assert(caughtError); + }, Deno.errors.PermissionDenied); }); unitTest({ perms: { read: true } }, function readTextFileSyncNotFound(): void { - let caughtError = false; - let data; - try { - data = Deno.readTextFileSync("bad_filename"); - } catch (e) { - caughtError = true; - assert(e instanceof Deno.errors.NotFound); - } - assert(caughtError); - assert(data === undefined); + assertThrows(() => { + Deno.readTextFileSync("bad_filename"); + }, Deno.errors.NotFound); }); unitTest( @@ -69,14 +59,9 @@ unitTest({ perms: { read: true } }, async function readTextFileByUrl(): Promise< unitTest({ perms: { read: false } }, async function readTextFilePerm(): Promise< void > { - let caughtError = false; - try { + await assertThrowsAsync(async () => { await Deno.readTextFile("cli/tests/fixture.json"); - } catch (e) { - caughtError = true; - assert(e instanceof Deno.errors.PermissionDenied); - } - assert(caughtError); + }, Deno.errors.PermissionDenied); }); unitTest({ perms: { read: true } }, function readTextFileSyncLoop(): void { |