fix: wrong usage of assertThrowsAsync which without await keyword (#295)

This commit is contained in:
Axetroy 2019-03-20 01:22:33 +08:00 committed by Ryan Dahl
parent 0bb040e8d4
commit 59adafe867
5 changed files with 19 additions and 15 deletions

View File

@ -1,6 +1,10 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts"; 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 { emptyDir, emptyDirSync } from "./empty_dir.ts";
import * as path from "./path/mod.ts"; import * as path from "./path/mod.ts";
@ -63,12 +67,12 @@ test(async function emptyDirIfItExist() {
assertEquals(stat.isDirectory(), true); assertEquals(stat.isDirectory(), true);
// nest directory have been remove // nest directory have been remove
assertThrowsAsync(async () => { await assertThrowsAsync(async () => {
await Deno.stat(testNestDir); await Deno.stat(testNestDir);
}); });
// test file have been remove // test file have been remove
assertThrowsAsync(async () => { await assertThrowsAsync(async () => {
await Deno.stat(testDirFile); await Deno.stat(testDirFile);
}); });
} finally { } finally {
@ -102,12 +106,12 @@ test(function emptyDirSyncIfItExist() {
assertEquals(stat.isDirectory(), true); assertEquals(stat.isDirectory(), true);
// nest directory have been remove // nest directory have been remove
assertThrowsAsync(async () => { assertThrows(() => {
Deno.statSync(testNestDir); Deno.statSync(testNestDir);
}); });
// test file have been remove // test file have been remove
assertThrowsAsync(async () => { assertThrows(() => {
Deno.statSync(testDirFile); Deno.statSync(testDirFile);
}); });
} finally { } finally {

View File

@ -12,7 +12,7 @@ test(async function ensureDirIfItNotExist() {
await ensureDir(testDir); await ensureDir(testDir);
assertThrowsAsync(async () => { await assertThrowsAsync(async () => {
await Deno.stat(testDir).then(() => { await Deno.stat(testDir).then(() => {
throw new Error("test dir should exists."); throw new Error("test dir should exists.");
}); });
@ -44,7 +44,7 @@ test(async function ensureDirIfItExist() {
await ensureDir(testDir); await ensureDir(testDir);
assertThrowsAsync(async () => { await assertThrowsAsync(async () => {
await Deno.stat(testDir).then(() => { await Deno.stat(testDir).then(() => {
throw new Error("test dir should still exists."); throw new Error("test dir should still exists.");
}); });

View File

@ -12,7 +12,7 @@ test(async function ensureFileIfItNotExist() {
await ensureFile(testFile); await ensureFile(testFile);
assertThrowsAsync(async () => { await assertThrowsAsync(async () => {
await Deno.stat(testFile).then(() => { await Deno.stat(testFile).then(() => {
throw new Error("test file should exists."); throw new Error("test file should exists.");
}); });
@ -44,7 +44,7 @@ test(async function ensureFileIfItExist() {
await ensureFile(testFile); await ensureFile(testFile);
assertThrowsAsync(async () => { await assertThrowsAsync(async () => {
await Deno.stat(testFile).then(() => { await Deno.stat(testFile).then(() => {
throw new Error("test file should exists."); throw new Error("test file should exists.");
}); });

View File

@ -240,7 +240,7 @@ test(function moveSyncFileIfDestExists() {
); );
// move again with overwrite // move again with overwrite
assertThrowsAsync( assertThrows(
() => { () => {
moveSync(srcFile, destFile, { overwrite: true }); moveSync(srcFile, destFile, { overwrite: true });
throw new Error("should not throw error"); throw new Error("should not throw error");

View File

@ -113,27 +113,27 @@ Using `assertThrowsAsync()`:
```ts ```ts
test(async function doesThrow() { test(async function doesThrow() {
assertThrowsAsync(async () => { await assertThrowsAsync(async () => {
throw new TypeError("hello world!"); throw new TypeError("hello world!");
}); });
assertThrowsAsync(async () => { await assertThrowsAsync(async () => {
throw new TypeError("hello world!"); throw new TypeError("hello world!");
}, TypeError); }, TypeError);
assertThrowsAsync( await assertThrowsAsync(
async () => { async () => {
throw new TypeError("hello world!"); throw new TypeError("hello world!");
}, },
TypeError, TypeError,
"hello" "hello"
); );
assertThrowsAsync(async () => { await assertThrowsAsync(async () => {
return Promise.reject(new Error()); return Promise.reject(new Error());
}); });
}); });
// This test will not pass // This test will not pass
test(async function fails() { test(async function fails() {
assertThrowsAsync(async () => { await assertThrowsAsync(async () => {
console.log("Hello world"); console.log("Hello world");
}); });
}); });