| 1 | import _Ajv from "../ajv" |
| 2 | import chai from "../chai" |
| 3 | chai.should() |
| 4 | |
| 5 | describe("issue #182, NaN validation", () => { |
| 6 | const ajv = new _Ajv({strictTypes: false}) |
| 7 | |
| 8 | it("should pass minimum/maximum validation without type", () => { |
| 9 | testNaN(ajv, {minimum: 1}, true) |
| 10 | testNaN(ajv, {maximum: 1}, true) |
| 11 | }) |
| 12 | |
| 13 | it("should NOT pass minimum/maximum validation without type when strict: false", () => { |
| 14 | const _ajv = new _Ajv({strict: false}) |
| 15 | testNaN(_ajv, {minimum: 1}, false) |
| 16 | testNaN(_ajv, {maximum: 1}, false) |
| 17 | }) |
| 18 | |
| 19 | it("should not pass minimum/maximum validation with type", () => { |
| 20 | testNaN(ajv, {type: "number", minimum: 1}, false) |
| 21 | testNaN(ajv, {type: "number", maximum: 1}, false) |
| 22 | }) |
| 23 | |
| 24 | it("should pass type: number validation when strict: false", () => { |
| 25 | const _ajv = new _Ajv({strict: false}) |
| 26 | testNaN(_ajv, {type: "number"}, true) |
| 27 | }) |
| 28 | |
| 29 | it("should not pass type: number validation (changed in v7 - strict by default)", () => { |
| 30 | testNaN(ajv, {type: "number"}, false) |
| 31 | }) |
| 32 | |
| 33 | it("should not pass type: integer validation", () => { |
| 34 | testNaN(ajv, {type: "integer"}, false) |
| 35 | }) |
| 36 | |
| 37 | function testNaN(_ajv, schema, NaNisValid) { |
| 38 | const validate = _ajv.compile(schema) |
| 39 | validate(NaN).should.equal(NaNisValid) |
| 40 | } |
| 41 | }) |