forked from ajv-validator/ajv
/
strictNumbers.spec.js
54 lines (44 loc) · 1.54 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
48
49
50
51
52
53
54
'use strict';
var Ajv = require('../ajv');
describe('structNumbers option', function() {
var ajv;
describe('strictNumbers default', function() {
beforeEach(function () {
ajv = new Ajv();
});
it('should NOT fail validation for NaN as type number', function() {
var validate = ajv.compile({type: 'number'});
validate(NaN).should.equal(true);
});
it('should not impact failing validation for NaN as type integer', function() {
var validate = ajv.compile({type: 'integer'});
validate(NaN).should.equal(false);
});
});
describe('strictNumbers = false', function() {
beforeEach(function () {
ajv = new Ajv({strictNumbers: false});
});
it('should NOT fail validation for NaN as type number', function() {
var validate = ajv.compile({type: 'number'});
validate(NaN).should.equal(true);
});
it('should not impact failing validation for NaN as type integer', function() {
var validate = ajv.compile({type: 'integer'});
validate(NaN).should.equal(false);
});
});
describe('strictNumbers = true', function() {
beforeEach(function () {
ajv = new Ajv({strictNumbers: true});
});
it('should fail validation for NaN as type number', function() {
var validate = ajv.compile({type: 'number'});
validate(NaN).should.equal(false);
});
it('should not impact failing validation for NaN as type integer', function() {
var validate = ajv.compile({type: 'integer'});
validate(NaN).should.equal(false);
});
});
});