forked from colinhacks/zod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nonNullable.test.ts
39 lines (31 loc) · 937 Bytes
/
nonNullable.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// @ts-ignore TS6133
import { expect, test } from "@jest/globals";
import * as z from "../index";
test("parses a number correctly using z....nonNullable()", () => {
const a = z.nullable(z.number()).nonNullable();
type a = z.infer<typeof a>;
const foo: a = a.parse(5);
expect(foo).toEqual(5);
});
test("parses a number correctly using z.nonNullable(...)", () => {
const a = z.nonNullable(z.any());
type a = z.infer<typeof a>;
const foo: a = a.parse(5);
expect(foo).toEqual(5);
});
test("fails is passed null", () => {
const a = z.nullable(z.any()).nonNullable();
expect(() => {
a.parse(null);
}).toThrow(z.ZodError)
});
test("fails is passed undefined", () => {
const a = z.nullable(z.any()).nonNullable();
expect(() => {
a.parse(undefined);
}).toThrow(z.ZodError)
});
test("unwrap", () => {
const unwrapped = z.any().nonNullable().unwrap();
expect(unwrapped).toBeInstanceOf(z.ZodAny);
});