summaryrefslogtreecommitdiff
path: root/cli/tests/unit/read_dir_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/unit/read_dir_test.ts')
-rw-r--r--cli/tests/unit/read_dir_test.ts48
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);
});