forked from colinhacks/zod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
record.tests.ts
48 lines (41 loc) · 999 Bytes
/
record.tests.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
40
41
42
43
44
45
46
47
48
import * as z from '..';
import { util } from '../helpers/util';
const booleanRecord = z.record(z.boolean());
type booleanRecord = z.infer<typeof booleanRecord>;
test('type inference', () => {
const f1: util.AssertEqual<booleanRecord, Record<string, boolean>> = true;
f1;
});
test('methods', () => {
booleanRecord.toJSON();
booleanRecord.optional();
booleanRecord.nullable();
});
test('string record parse - pass', () => {
booleanRecord.parse({
k1: true,
k2: false,
1234: false,
});
});
test('string record parse - fail', () => {
const badCheck = () =>
booleanRecord.parse({
asdf: 1234,
} as any);
expect(badCheck).toThrow();
});
test('string record parse - fail', () => {
const badCheck = () =>
booleanRecord.parse({
asdf: {},
} as any);
expect(badCheck).toThrow();
});
test('string record parse - fail', () => {
const badCheck = () =>
booleanRecord.parse({
asdf: [],
} as any);
expect(badCheck).toThrow();
});