summaryrefslogtreecommitdiff
path: root/cli/tests/unit/write_text_file_test.ts
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2020-06-25 06:57:08 +0800
committerGitHub <noreply@github.com>2020-06-25 00:57:08 +0200
commit87f8f99c49e62c06f85bb453a7c12b32634c3bef (patch)
treee8f966f981a9f825ca1f22fe8d39642c448a9c62 /cli/tests/unit/write_text_file_test.ts
parent6bbe52fba33e440e113bca423b5eae0d1f320c49 (diff)
refactor(cli/tests/unit) to use assertThrows (#6459)
Diffstat (limited to 'cli/tests/unit/write_text_file_test.ts')
-rw-r--r--cli/tests/unit/write_text_file_test.ts43
1 files changed, 14 insertions, 29 deletions
diff --git a/cli/tests/unit/write_text_file_test.ts b/cli/tests/unit/write_text_file_test.ts
index d72fa722e..fcc8ba728 100644
--- a/cli/tests/unit/write_text_file_test.ts
+++ b/cli/tests/unit/write_text_file_test.ts
@@ -1,4 +1,9 @@
-import { unitTest, assert, assertEquals } from "./test_util.ts";
+import {
+ unitTest,
+ assertEquals,
+ assertThrows,
+ assertThrowsAsync,
+} from "./test_util.ts";
unitTest(
{ perms: { read: true, write: true } },
@@ -28,27 +33,17 @@ unitTest(
unitTest({ perms: { write: true } }, function writeTextFileSyncFail(): void {
const filename = "/baddir/test.txt";
// The following should fail because /baddir doesn't exist (hopefully).
- let caughtError = false;
- try {
+ assertThrows(() => {
Deno.writeTextFileSync(filename, "hello");
- } catch (e) {
- caughtError = true;
- assert(e instanceof Deno.errors.NotFound);
- }
- assert(caughtError);
+ }, Deno.errors.NotFound);
});
unitTest({ perms: { write: false } }, function writeTextFileSyncPerm(): void {
const filename = "/baddir/test.txt";
// The following should fail due to no write permission
- let caughtError = false;
- try {
+ assertThrows(() => {
Deno.writeTextFileSync(filename, "Hello");
- } catch (e) {
- caughtError = true;
- assert(e instanceof Deno.errors.PermissionDenied);
- }
- assert(caughtError);
+ }, Deno.errors.PermissionDenied);
});
unitTest(
@@ -81,14 +76,9 @@ unitTest(
async function writeTextFileNotFound(): Promise<void> {
const filename = "/baddir/test.txt";
// The following should fail because /baddir doesn't exist (hopefully).
- let caughtError = false;
- try {
+ await assertThrowsAsync(async () => {
await Deno.writeTextFile(filename, "Hello");
- } catch (e) {
- caughtError = true;
- assert(e instanceof Deno.errors.NotFound);
- }
- assert(caughtError);
+ }, Deno.errors.NotFound);
}
);
@@ -97,13 +87,8 @@ unitTest(
async function writeTextFilePerm(): Promise<void> {
const filename = "/baddir/test.txt";
// The following should fail due to no write permission
- let caughtError = false;
- try {
+ await assertThrowsAsync(async () => {
await Deno.writeTextFile(filename, "Hello");
- } catch (e) {
- caughtError = true;
- assert(e instanceof Deno.errors.PermissionDenied);
- }
- assert(caughtError);
+ }, Deno.errors.PermissionDenied);
}
);