Skip to content

Commit 9f1c0d8

Browse files
committed
refactor(unit/fs/fs_handle_test): use assertRejects for permission error test
1 parent 2c09dad commit 9f1c0d8

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

Diff for: tests/unit_node/_fs/_fs_handle_test.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as path from "@std/path";
33
import { Buffer } from "node:buffer";
44
import * as fs from "node:fs/promises";
5-
import { assert, assertEquals } from "@std/assert";
5+
import { assert, assertEquals, assertRejects } from "@std/assert";
66

77
const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
88
const testData = path.resolve(moduleDir, "testdata", "hello.txt");
@@ -286,14 +286,11 @@ Deno.test({
286286
const nobodyUid = 65534;
287287
const nobodyGid = 65534;
288288

289-
try {
290-
await fileHandle.chown(nobodyUid, nobodyGid);
291-
} catch (e) {
292-
assert(
293-
e instanceof Deno.errors.PermissionDenied,
294-
"Expected permissionDenied error",
295-
);
296-
}
289+
assertRejects(
290+
async () => await fileHandle.chown(nobodyUid, nobodyGid),
291+
Deno.errors.PermissionDenied,
292+
"Operation not permitted",
293+
);
297294

298295
const realUid = Deno.uid() || 1000;
299296
const realGid = Deno.gid() || 1000;

0 commit comments

Comments
 (0)