-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmockString.spec.ts
76 lines (73 loc) · 1.59 KB
/
mockString.spec.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { describe, expect, it } from "vitest";
import {
parse,
parseAsync,
string,
stringAsync,
maxLength,
minLength,
length,
cuid2,
email,
emoji,
imei,
ip,
ipv4,
ipv6,
isoDate,
isoDateTime,
isoTime,
isoTimeSecond,
isoTimestamp,
isoWeek,
ulid,
url,
uuid
} from "valibot";
import { Valimock } from "../Valimock.js";
const mockSchema = new Valimock().mock;
describe(`mockString`, () => {
it.each([
string(),
string([cuid2()]),
string([email()]),
string([emoji()]),
string([imei()]),
string([ip()]),
string([ipv4()]),
string([ipv6()]),
string([isoDate()]),
string([isoDateTime()]),
string([isoTime()]),
string([isoTimeSecond()]),
string([isoTimestamp()]),
string([isoWeek()]),
string([ulid()]),
string([url()]),
string([uuid()]),
string([minLength(4)]),
string([maxLength(16)]),
string([length(4)]),
string([minLength(4)]),
string([maxLength(16)]),
string([length(4)])
])(`should generate valid mock data (%#)`, (schema) => {
const result = mockSchema(schema);
expect(parse(schema, result)).toStrictEqual(result);
});
it.each([
stringAsync(),
stringAsync([minLength(4)]),
stringAsync([maxLength(16)]),
stringAsync([length(4)]),
stringAsync([minLength(4)]),
stringAsync([maxLength(16)]),
stringAsync([length(4)])
])(
`should generate valid mock data with async validation (%#)`,
async (schema) => {
const result = mockSchema(schema);
await expect(parseAsync(schema, result)).resolves.toStrictEqual(result);
}
);
});