-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmockEnum.spec.ts
56 lines (49 loc) · 1.24 KB
/
mockEnum.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
/* eslint-disable @typescript-eslint/prefer-enum-initializers */
/* eslint-disable @typescript-eslint/prefer-literal-enum-member */
/* eslint-disable no-bitwise */
import { describe, expect, it } from "vitest";
import { parse, parseAsync, enum_, enumAsync } from "valibot";
import { Valimock } from "../Valimock.js";
const mockSchema = new Valimock().mock;
describe(`mockEnum`, () => {
enum States {
INITIAL = 0,
FETCHING = 1,
RESOLVED = 2,
REJECTED = 3
}
enum Flags {
JOIN = 1 << 0,
SPECTATE = 1 << 1,
PLAY = 1 << 2
}
enum Features {
FOO = `FOO`,
BAR = `BAR`,
BAZ = `BAZ`
}
enum Status {
RED,
YELLOW,
GREEN
}
it.each([enum_(States), enum_(Flags), enum_(Features), enum_(Status)])(
`should generate valid mock data (%#)`,
(schema) => {
const result = mockSchema(schema);
expect(parse(schema, result)).toStrictEqual(result);
}
);
it.each([
enumAsync(States),
enumAsync(Flags),
enumAsync(Features),
enumAsync(Status)
])(
`should generate valid mock data with async validation (%#)`,
async (schema) => {
const result = mockSchema(schema);
await expect(parseAsync(schema, result)).resolves.toStrictEqual(result);
}
);
});