forked from ajv-validator/ajv
/
strictNumbers.spec.js
47 lines (40 loc) · 1.51 KB
/
strictNumbers.spec.js
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
'use strict';
var Ajv = require('../ajv');
describe('structNumbers option', function() {
var ajv;
describe('strictNumbers default', testWithoutStrictNumbers(new Ajv()));
describe('strictNumbers = false', testWithoutStrictNumbers(new Ajv({strictNumbers: false})));
describe('strictNumbers = true', function() {
beforeEach(function () {
ajv = new Ajv({strictNumbers: true});
});
it('should fail validation for NaN/Infinity as type number', function() {
var validate = ajv.compile({type: 'number'});
validate(1).should.equal(true);
validate(NaN).should.equal(false);
validate(Infinity).should.equal(false);
});
it('should not impact validation for NaN as type integer', function() {
var validate = ajv.compile({type: 'integer'});
validate(1).should.equal(true);
validate(NaN).should.equal(false);
validate(Infinity).should.equal(true);
});
});
});
function testWithoutStrictNumbers(_ajv) {
return function () {
it('should NOT fail validation for NaN/Infinity as type number', function() {
var validate = _ajv.compile({type: 'number'});
validate(1).should.equal(true);
validate(NaN).should.equal(true);
validate(Infinity).should.equal(true);
});
it('should not impact validation for NaN/Infinity as type integer', function() {
var validate = _ajv.compile({type: 'integer'});
validate(1).should.equal(true);
validate(NaN).should.equal(false);
validate(Infinity).should.equal(true);
});
};
}