/
literal.spec.ts
42 lines (33 loc) · 1.16 KB
/
literal.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
/* eslint-disable unicorn/no-useless-undefined */
import { translate } from "../validation";
import { literal, literals } from "./literal";
describe("literal", () => {
const schema = literal("a");
it("accepts", () => {
expect(schema.accepts("a")).toBeTruthy();
expect(schema.accepts("d")).toBeFalsy();
expect(schema.accepts(undefined)).toBeFalsy();
});
it("validates", () => {
expect(schema.validate("a")).toBeUndefined();
expect(translate(schema.validate([]))).toEqual(
"value was of type array expected string or symbol or number"
);
expect(translate(schema.validate("d"))).toEqual("literal(a)");
});
});
describe("literals", () => {
const schema = literals("a", "b", "c");
it("accepts", () => {
expect(schema.accepts("a")).toBeTruthy();
expect(schema.accepts("d")).toBeFalsy();
expect(schema.accepts(undefined)).toBeFalsy();
});
it("validates", () => {
expect(schema.validate("a")).toBeUndefined();
expect(translate(schema.validate([]))).toEqual(
"value was of type array expected string or symbol or number"
);
expect(translate(schema.validate("d"))).toEqual("literal(a,b,c)");
});
});