From 20a84c2782b0578ce553ddef349545f7b5be1720 Mon Sep 17 00:00:00 2001 From: Milly Date: Mon, 12 Aug 2024 21:10:16 +0900 Subject: [PATCH] test[hasReadonly]: add tests --- as/readonly_test.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/as/readonly_test.ts b/as/readonly_test.ts index 2bc6dd2..820086d 100644 --- a/as/readonly_test.ts +++ b/as/readonly_test.ts @@ -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", async (t) => { await t.step("returns a property named predicate function", () => { @@ -155,3 +156,23 @@ Deno.test("asUnreadonly", async (t) => { }); }); }); + +Deno.test("hasReadonly

", async (t) => { + await t.step("returns true on AsReadonly predicate", () => { + const pred = asReadonly(is.Number); + assertEquals(hasReadonly(pred), true); + }); + + await t.step("returns true on non AsReadonly 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>(true); + } + }); +});