Debian Codegraph @

spec/issues/955_removeAdditional_custom_keywords.spec.ts

raw symbols ◀ ▶ SCIP
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 // @ts-ignore
38 validate(data).should.equal(true)
•39 // @ts-ignore
40 data.should.not.have.property("baz")
41
42 data = {
43 foo: " ba ",
44 baz: "",
45 }
•46 // @ts-ignore
47 validate(data).should.equal(false)
•48 // @ts-ignore
49 data.should.not.have.property("baz")
50 })
51 })