1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-27 17:49:08 -05:00

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.
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 {

View file

@ -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.");
});

View file

@ -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.");
});

View file

@ -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");

View file

@ -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");
});
});