Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make "properties" a dependency of "allRequired"
- Loading branch information
1 parent
13f692a
commit da6e030
Showing
4 changed files
with
55 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
var Ajv = require('ajv'); | ||
var ajvPack = require('ajv-pack'); | ||
var defFunc = require('../keywords/allRequired'); | ||
var defineKeywords = require('..'); | ||
var should = require('chai').should(); | ||
|
||
|
||
describe('keyword "allRequired"', function() { | ||
var ajvs = [ | ||
defFunc(new Ajv), | ||
defineKeywords(new Ajv, 'allRequired'), | ||
defineKeywords(new Ajv), | ||
defFunc(ajvPack.instance(new Ajv({sourceCode: true}))) | ||
]; | ||
|
||
ajvs.forEach(function (ajv, i) { | ||
it('should validate that all defined properties are present #' + i, function() { | ||
var schema = { | ||
properties: { | ||
foo: true, | ||
bar: true | ||
}, | ||
allRequired: true | ||
}; | ||
ajv.validate(schema, {foo: 1, bar: 2}) .should.equal(true); | ||
ajv.validate(schema, {foo: 1}) .should.equal(false); | ||
}); | ||
}); | ||
|
||
ajvs.forEach(function (ajv, i) { | ||
it('should throw when properties is absent #' + i, function() { | ||
should.throw(function() { | ||
ajv.compile({ allRequired: true }); | ||
}); | ||
}); | ||
}); | ||
|
||
ajvs.forEach(function (ajv, i) { | ||
it('should throw when allRequired schema is invalid #' + i, function() { | ||
should.throw(function() { | ||
ajv.compile({ properties: {foo: true}, allRequired: 1 }); | ||
}); | ||
}); | ||
}); | ||
}); |
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