-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathobject.test.ts
73 lines (57 loc) · 2.28 KB
/
object.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
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
import { strict as assert } from "assert";
import { compileSchema } from "../compileSchema";
describe("keyword : object : validate", () => {
describe("maxProperties", () => {
it("should return an error if maxProperties is exceeded", () => {
const node = compileSchema({
type: "object",
maxProperties: 1
});
const { errors } = node.validate({ a: "1", b: "2" });
assert.equal(errors.length, 1);
assert.deepEqual(errors[0].code, "max-properties-error");
});
it("should NOT return an error if property count is equal to maxProperties", () => {
const node = compileSchema({
type: "object",
maxProperties: 2
});
const { errors } = node.validate({ a: "1", b: "2" });
assert.equal(errors.length, 0);
});
it("should return an error if maxProperties of nested properties is exceeded", () => {
// tests validation walking through properties
const node = compileSchema({
type: "object",
properties: {
header: {
type: "object",
maxProperties: 1
}
}
});
const { errors } = node.validate({ header: { a: "1", b: "2" } });
assert.equal(errors.length, 1);
assert.deepEqual(errors[0].code, "max-properties-error");
});
});
describe("minProperties", () => {
it("should return an error if property count is below minProperties ", () => {
const node = compileSchema({
type: "object",
minProperties: 2
});
const { errors } = node.validate({ a: "1" });
assert.equal(errors.length, 1);
assert.deepEqual(errors[0].code, "min-properties-error");
});
it("should NOT return an error if property count is equal to minProperties ", () => {
const node = compileSchema({
type: "object",
minProperties: 2
});
const { errors } = node.validate({ a: "1", b: "2" });
assert.equal(errors.length, 0);
});
});
});