forked from ajv-validator/ajv
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option for strictNumbers. Resolves ajv-validator#1128.
- Loading branch information
Issac Gerges
committed
May 22, 2020
1 parent
0b14f60
commit 6727a79
Showing
6 changed files
with
80 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'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/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); | ||
}); | ||
}); | ||
|
||
describe('strictNumbers = false', function() { | ||
beforeEach(function () { | ||
ajv = new Ajv({strictNumbers: false}); | ||
}); | ||
|
||
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); | ||
}); | ||
}); | ||
|
||
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); | ||
}); | ||
}); | ||
}); |