Skip to content

Commit 20a84c2

Browse files
committed
test[hasReadonly]: add tests
1 parent f2f7d3d commit 20a84c2

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

as/readonly_test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { assertEquals } from "@std/assert";
22
import { assertType } from "@std/testing/types";
33
import { type Equal, testWithExamples } from "../_testutil.ts";
44
import { is } from "../is/mod.ts";
5-
import { asReadonly, asUnreadonly } from "./readonly.ts";
5+
import type { AsReadonly } from "../_annotation.ts";
6+
import { asReadonly, asUnreadonly, hasReadonly } from "./readonly.ts";
67

78
Deno.test("asReadonly<T>", async (t) => {
89
await t.step("returns a property named predicate function", () => {
@@ -155,3 +156,23 @@ Deno.test("asUnreadonly<T>", async (t) => {
155156
});
156157
});
157158
});
159+
160+
Deno.test("hasReadonly<P>", async (t) => {
161+
await t.step("returns true on AsReadonly<T> predicate", () => {
162+
const pred = asReadonly(is.Number);
163+
assertEquals(hasReadonly(pred), true);
164+
});
165+
166+
await t.step("returns true on non AsReadonly<T> predicate", () => {
167+
const pred = is.Number;
168+
assertEquals(hasReadonly(pred), false);
169+
});
170+
171+
await t.step("predicated type is correct", () => {
172+
const pred = asReadonly(is.Number);
173+
type P = typeof pred;
174+
if (hasReadonly(pred)) {
175+
assertType<Equal<typeof pred, P & AsReadonly>>(true);
176+
}
177+
});
178+
});

0 commit comments

Comments
 (0)