mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
fix: wrong usage of assertThrowsAsync which without await keyword (#295)
This commit is contained in:
parent
0bb040e8d4
commit
59adafe867
@ -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 {
|
||||||
|
@ -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.");
|
||||||
});
|
});
|
||||||
|
@ -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.");
|
||||||
});
|
});
|
||||||
|
@ -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");
|
||||||
|
@ -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");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user