-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathconst.test.ts
More file actions
35 lines (28 loc) · 1.27 KB
/
const.test.ts
File metadata and controls
35 lines (28 loc) · 1.27 KB
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
import { strict as assert } from "assert";
import { compileSchema } from "../compileSchema";
describe("keyword : const : validate", () => {
it("should return error if const does not match", () => {
const { errors } = compileSchema({ const: true }).validate(false);
assert.equal(errors.length, 1);
});
it("should NOT return error if const does match", () => {
const { errors } = compileSchema({ const: true }).validate(true);
assert.equal(errors.length, 0);
});
it("should return error if value is not null", () => {
const { errors } = compileSchema({ const: null }).validate("mi");
assert.equal(errors.length, 1);
});
it("should NOT return error if value is null", () => {
const { errors } = compileSchema({ const: null }).validate(null);
assert.equal(errors.length, 0);
});
it("should return error if object is not deep equal", () => {
const { errors } = compileSchema({ const: { a: { b: 2 } } }).validate({ a: { b: "2" } });
assert.equal(errors.length, 1);
});
it("should NOT return error if object is deep equal", () => {
const { errors } = compileSchema({ const: { a: { b: 2 } } }).validate({ a: { b: 2 } });
assert.equal(errors.length, 0);
});
});