-
Notifications
You must be signed in to change notification settings - Fork 0
/
validates_test.ts
41 lines (36 loc) · 1.06 KB
/
validates_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
40
41
import { isSchema, validateSchema } from "./validates.ts";
import { describe, expect, it } from "./dev_deps.ts";
import { StringSchema } from "./mod.ts";
import { SchemaError } from "./errors.ts";
describe("isSchema", () => {
it("should return false", () => {
expect(isSchema(null)).toBeFalsy();
expect(isSchema({})).toBeFalsy();
});
it("should pass when the value has functional assert property", () => {
expect(isSchema(new StringSchema())).toBeTruthy();
expect(isSchema({ assert: Function })).toBeTruthy();
});
});
describe("validateSchema", () => {
it("should return success validation result", () => {
expect(validateSchema({ assert: () => {} }, "")).toEqual({
pass: true,
data: "",
});
expect(validateSchema({ assert: () => {} }, {})).toEqual({
pass: true,
data: {},
});
});
it("should return fail validation result", () => {
expect(validateSchema({
assert: () => {
throw Error();
},
}, "")).toEqual({
pass: false,
errors: [new SchemaError()],
});
});
});