Skip to content

Commit

Permalink
test[hasReadonly]: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Milly committed Aug 12, 2024
1 parent f2f7d3d commit 20a84c2
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion as/readonly_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { assertEquals } from "@std/assert";
import { assertType } from "@std/testing/types";
import { type Equal, testWithExamples } from "../_testutil.ts";
import { is } from "../is/mod.ts";
import { asReadonly, asUnreadonly } from "./readonly.ts";
import type { AsReadonly } from "../_annotation.ts";
import { asReadonly, asUnreadonly, hasReadonly } from "./readonly.ts";

Deno.test("asReadonly<T>", async (t) => {
await t.step("returns a property named predicate function", () => {
Expand Down Expand Up @@ -155,3 +156,23 @@ Deno.test("asUnreadonly<T>", async (t) => {
});
});
});

Deno.test("hasReadonly<P>", async (t) => {
await t.step("returns true on AsReadonly<T> predicate", () => {
const pred = asReadonly(is.Number);
assertEquals(hasReadonly(pred), true);
});

await t.step("returns true on non AsReadonly<T> predicate", () => {
const pred = is.Number;
assertEquals(hasReadonly(pred), false);
});

await t.step("predicated type is correct", () => {
const pred = asReadonly(is.Number);
type P = typeof pred;
if (hasReadonly(pred)) {
assertType<Equal<typeof pred, P & AsReadonly>>(true);
}
});
});

0 comments on commit 20a84c2

Please sign in to comment.