Skip to content

Commit f2f7d3d

Browse files
committed
test[hasOptional]: add tests
1 parent 3d2cf21 commit f2f7d3d

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

as/optional_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 { asOptional, asUnoptional } from "./optional.ts";
5+
import type { AsOptional } from "../_annotation.ts";
6+
import { asOptional, asUnoptional, hasOptional } from "./optional.ts";
67

78
Deno.test("asOptional<T>", async (t) => {
89
await t.step("returns a property named predicate function", () => {
@@ -153,3 +154,23 @@ Deno.test("asUnoptional<T>", async (t) => {
153154
});
154155
});
155156
});
157+
158+
Deno.test("hasOptional<P>", async (t) => {
159+
await t.step("returns true on AsOptional<T> predicate", () => {
160+
const pred = asOptional(is.Number);
161+
assertEquals(hasOptional(pred), true);
162+
});
163+
164+
await t.step("returns true on non AsOptional<T> predicate", () => {
165+
const pred = is.Number;
166+
assertEquals(hasOptional(pred), false);
167+
});
168+
169+
await t.step("predicated type is correct", () => {
170+
const pred = asOptional(is.Number);
171+
type P = typeof pred;
172+
if (hasOptional(pred)) {
173+
assertType<Equal<typeof pred, P & AsOptional<number>>>(true);
174+
}
175+
});
176+
});

0 commit comments

Comments
 (0)