Skip to content

Commit

Permalink
fix(fs): improve exists() test coverage (#3898)
Browse files Browse the repository at this point in the history
* fix(test): improve exists test coverage

* fix(test): improve exists test coverage
  • Loading branch information
vasucp1207 authored Dec 5, 2023
1 parent 8532be7 commit 9a55a6e
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion fs/exists_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../assert/mod.ts";
import { assert, assertEquals, assertStringIncludes } from "../assert/mod.ts";
import * as path from "../path/mod.ts";
import { exists, existsSync } from "./exists.ts";

Expand Down Expand Up @@ -324,3 +324,45 @@ Deno.test("existsSync() returns true for an existing dir symlink", function () {
Deno.removeSync(tempDirPath, { recursive: true });
}
});

Deno.test("exists() returns false when both isDirectory and isFile sets true", async function () {
const tempDirPath = await Deno.makeTempDir();
try {
assertEquals(
await exists(tempDirPath, {
isDirectory: true,
isFile: true,
}),
true,
);
} catch (error) {
assert(error instanceof TypeError);
assertStringIncludes(
error.message,
"ExistsOptions.options.isDirectory and ExistsOptions.options.isFile must not be true together.",
);
} finally {
await Deno.remove(tempDirPath, { recursive: true });
}
});

Deno.test("existsSync() returns false when both isDirectory and isFile sets true", async function () {
const tempDirPath = await Deno.makeTempDir();
try {
assertEquals(
await existsSync(tempDirPath, {
isDirectory: true,
isFile: true,
}),
true,
);
} catch (error) {
assert(error instanceof TypeError);
assertStringIncludes(
error.message,
"ExistsOptions.options.isDirectory and ExistsOptions.options.isFile must not be true together.",
);
} finally {
await Deno.remove(tempDirPath, { recursive: true });
}
});

0 comments on commit 9a55a6e

Please sign in to comment.