mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
refactor(cli/tests/unit) to use assertThrows (#6459)
This commit is contained in:
parent
6bbe52fba3
commit
87f8f99c49
28 changed files with 404 additions and 913 deletions
|
@ -3,6 +3,8 @@ import {
|
|||
unitTest,
|
||||
assert,
|
||||
assertEquals,
|
||||
assertThrows,
|
||||
assertThrowsAsync,
|
||||
pathToAbsoluteFileUrl,
|
||||
} from "./test_util.ts";
|
||||
|
||||
|
@ -27,27 +29,15 @@ unitTest({ perms: { read: true } }, function readFileSyncUrl(): void {
|
|||
});
|
||||
|
||||
unitTest({ perms: { read: false } }, function readFileSyncPerm(): void {
|
||||
let caughtError = false;
|
||||
try {
|
||||
assertThrows(() => {
|
||||
Deno.readFileSync("cli/tests/fixture.json");
|
||||
} catch (e) {
|
||||
caughtError = true;
|
||||
assert(e instanceof Deno.errors.PermissionDenied);
|
||||
}
|
||||
assert(caughtError);
|
||||
}, Deno.errors.PermissionDenied);
|
||||
});
|
||||
|
||||
unitTest({ perms: { read: true } }, function readFileSyncNotFound(): void {
|
||||
let caughtError = false;
|
||||
let data;
|
||||
try {
|
||||
data = Deno.readFileSync("bad_filename");
|
||||
} catch (e) {
|
||||
caughtError = true;
|
||||
assert(e instanceof Deno.errors.NotFound);
|
||||
}
|
||||
assert(caughtError);
|
||||
assert(data === undefined);
|
||||
assertThrows(() => {
|
||||
Deno.readFileSync("bad_filename");
|
||||
}, Deno.errors.NotFound);
|
||||
});
|
||||
|
||||
unitTest({ perms: { read: true } }, async function readFileUrl(): Promise<
|
||||
|
@ -77,14 +67,9 @@ unitTest({ perms: { read: true } }, async function readFileSuccess(): Promise<
|
|||
unitTest({ perms: { read: false } }, async function readFilePerm(): Promise<
|
||||
void
|
||||
> {
|
||||
let caughtError = false;
|
||||
try {
|
||||
await assertThrowsAsync(async () => {
|
||||
await Deno.readFile("cli/tests/fixture.json");
|
||||
} catch (e) {
|
||||
caughtError = true;
|
||||
assert(e instanceof Deno.errors.PermissionDenied);
|
||||
}
|
||||
assert(caughtError);
|
||||
}, Deno.errors.PermissionDenied);
|
||||
});
|
||||
|
||||
unitTest({ perms: { read: true } }, function readFileSyncLoop(): void {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue