MCPcopy
hub / github.com/ajv-validator/ajv / testTree

Function testTree

spec/dynamic-ref.spec.ts:75–123  ·  view source on GitHub ↗
(treeSchema: SchemaObject, strictTreeSchema: SchemaObject)

Source from the content-addressed store, hash-verified

73 })
74
75 function testTree(treeSchema: SchemaObject, strictTreeSchema: SchemaObject): void {
76 const validTree = {
77 data: 1,
78 children: [
79 {
80 data: 2,
81 children: [{data: 3}],
82 },
83 ],
84 }
85
86 const invalidTree = {
87 data: 1,
88 children: [
89 {
90 data: 2,
91 children: {},
92 },
93 ],
94 }
95
96 const treeWithExtra = {
97 data: 1,
98 children: [{data: 2, extra: 2}],
99 }
100
101 const treeWithDeepExtra = {
102 data: 1,
103 children: [
104 {
105 data: 2,
106 children: [{data: 3, extra: 3}],
107 },
108 ],
109 }
110
111 ajvs.forEach((ajv) => {
112 const validate = ajv.compile(treeSchema)
113 assert.strictEqual(validate(validTree), true)
114 assert.strictEqual(validate(invalidTree), false)
115 assert.strictEqual(validate(treeWithExtra), true) // because unevaluated props allowed
116 assert.strictEqual(validate(treeWithDeepExtra), true) // because unevaluated props allowed
117 const validateStrict = ajv.compile(strictTreeSchema)
118 assert.strictEqual(validateStrict(validTree), true)
119 assert.strictEqual(validateStrict(invalidTree), false)
120 assert.strictEqual(validateStrict(treeWithExtra), false) // because "extra" is "unevaluated"
121 assert.strictEqual(validateStrict(treeWithDeepExtra), false) // because "extra" is "unevaluated"
122 })
123 }
124})

Callers 1

Calls 2

validateFunction · 0.85
compileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…