Debian Codegraph @

spec/issues/955_removeAdditional_custom_keywords.spec.ts

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 import _Ajv from "../ajv"
2 import chai from "../chai"
3 chai.should()
4
5 describe("issue #955: option removeAdditional breaks user-defined keywords", () => {
6 it("should support user-defined keywords with option removeAdditional", () => {
7 const ajv = new _Ajv({removeAdditional: "all"})
8
9 ajv.addKeyword({
10 keyword: "minTrimmedLength",
11 type: "string",
12 compile: function (schema: number) {
13 return function (str: string): boolean {
14 return str.trim().length >= schema
15 }
16 },
17 metaSchema: {type: "integer"},
18 })
19
20 const schema = {
21 type: "object",
22 properties: {
23 foo: {
24 type: "string",
25 minTrimmedLength: 3,
26 },
27 },
28 required: ["foo"],
29 }
30
31 const validate = ajv.compile(schema)
32
33 let data = {
34 foo: " bar ",
35 baz: "",
36 }
37 validate(data).should.equal(true)
38 data.should.not.have.property("baz")
39
40 data = {
41 foo: " ba ",
42 baz: "",
43 }
44 validate(data).should.equal(false)
45 data.should.not.have.property("baz")
46 })
47 })