From 59adafe86710038c6864fc0686f0292bf7fd9b1d Mon Sep 17 00:00:00 2001 From: Axetroy Date: Wed, 20 Mar 2019 01:22:33 +0800 Subject: [PATCH] fix: wrong usage of assertThrowsAsync which without await keyword (#295) --- fs/empty_dir_test.ts | 14 +++++++++----- fs/ensure_dir_test.ts | 4 ++-- fs/ensure_file_test.ts | 4 ++-- fs/move_test.ts | 2 +- testing/README.md | 10 +++++----- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/fs/empty_dir_test.ts b/fs/empty_dir_test.ts index d4a0de77a7..d91c497a74 100644 --- a/fs/empty_dir_test.ts +++ b/fs/empty_dir_test.ts @@ -1,6 +1,10 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import { test } from "../testing/mod.ts"; -import { assertEquals, assertThrowsAsync } from "../testing/asserts.ts"; +import { + assertEquals, + assertThrows, + assertThrowsAsync +} from "../testing/asserts.ts"; import { emptyDir, emptyDirSync } from "./empty_dir.ts"; import * as path from "./path/mod.ts"; @@ -63,12 +67,12 @@ test(async function emptyDirIfItExist() { assertEquals(stat.isDirectory(), true); // nest directory have been remove - assertThrowsAsync(async () => { + await assertThrowsAsync(async () => { await Deno.stat(testNestDir); }); // test file have been remove - assertThrowsAsync(async () => { + await assertThrowsAsync(async () => { await Deno.stat(testDirFile); }); } finally { @@ -102,12 +106,12 @@ test(function emptyDirSyncIfItExist() { assertEquals(stat.isDirectory(), true); // nest directory have been remove - assertThrowsAsync(async () => { + assertThrows(() => { Deno.statSync(testNestDir); }); // test file have been remove - assertThrowsAsync(async () => { + assertThrows(() => { Deno.statSync(testDirFile); }); } finally { diff --git a/fs/ensure_dir_test.ts b/fs/ensure_dir_test.ts index abf34221f3..2e7936ae9c 100644 --- a/fs/ensure_dir_test.ts +++ b/fs/ensure_dir_test.ts @@ -12,7 +12,7 @@ test(async function ensureDirIfItNotExist() { await ensureDir(testDir); - assertThrowsAsync(async () => { + await assertThrowsAsync(async () => { await Deno.stat(testDir).then(() => { throw new Error("test dir should exists."); }); @@ -44,7 +44,7 @@ test(async function ensureDirIfItExist() { await ensureDir(testDir); - assertThrowsAsync(async () => { + await assertThrowsAsync(async () => { await Deno.stat(testDir).then(() => { throw new Error("test dir should still exists."); }); diff --git a/fs/ensure_file_test.ts b/fs/ensure_file_test.ts index b98d7c4e02..2199e36058 100644 --- a/fs/ensure_file_test.ts +++ b/fs/ensure_file_test.ts @@ -12,7 +12,7 @@ test(async function ensureFileIfItNotExist() { await ensureFile(testFile); - assertThrowsAsync(async () => { + await assertThrowsAsync(async () => { await Deno.stat(testFile).then(() => { throw new Error("test file should exists."); }); @@ -44,7 +44,7 @@ test(async function ensureFileIfItExist() { await ensureFile(testFile); - assertThrowsAsync(async () => { + await assertThrowsAsync(async () => { await Deno.stat(testFile).then(() => { throw new Error("test file should exists."); }); diff --git a/fs/move_test.ts b/fs/move_test.ts index f8d7a6f447..aa49b4cca8 100644 --- a/fs/move_test.ts +++ b/fs/move_test.ts @@ -240,7 +240,7 @@ test(function moveSyncFileIfDestExists() { ); // move again with overwrite - assertThrowsAsync( + assertThrows( () => { moveSync(srcFile, destFile, { overwrite: true }); throw new Error("should not throw error"); diff --git a/testing/README.md b/testing/README.md index 3d49c5a765..684d5d4bc3 100644 --- a/testing/README.md +++ b/testing/README.md @@ -113,27 +113,27 @@ Using `assertThrowsAsync()`: ```ts test(async function doesThrow() { - assertThrowsAsync(async () => { + await assertThrowsAsync(async () => { throw new TypeError("hello world!"); }); - assertThrowsAsync(async () => { + await assertThrowsAsync(async () => { throw new TypeError("hello world!"); }, TypeError); - assertThrowsAsync( + await assertThrowsAsync( async () => { throw new TypeError("hello world!"); }, TypeError, "hello" ); - assertThrowsAsync(async () => { + await assertThrowsAsync(async () => { return Promise.reject(new Error()); }); }); // This test will not pass test(async function fails() { - assertThrowsAsync(async () => { + await assertThrowsAsync(async () => { console.log("Hello world"); }); });