Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: strictKeywords option to report unknown keywords, closes #781
- Loading branch information
1 parent
9a28689
commit e993bd6
Showing
6 changed files
with
99 additions
and
2 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'); | ||
var should = require('../chai').should(); | ||
|
||
|
||
describe('strictKeywords option', function() { | ||
describe('strictKeywords = false', function() { | ||
it('should NOT throw an error or log a warning given an unknown keyword', function() { | ||
var output = {}; | ||
var ajv = new Ajv({ | ||
strictKeywords: false, | ||
logger: getLogger(output) | ||
}); | ||
var schema = { | ||
properties: {}, | ||
unknownKeyword: 1 | ||
}; | ||
|
||
ajv.compile(schema); | ||
should.not.exist(output.warning); | ||
}); | ||
}); | ||
|
||
describe('strictKeywords = true', function() { | ||
it('should throw an error given an unknown keyword in the schema root when strictKeywords is true', function() { | ||
var ajv = new Ajv({strictKeywords: true}); | ||
var schema = { | ||
properties: {}, | ||
unknownKeyword: 1 | ||
}; | ||
should.throw(function() { ajv.compile(schema); }); | ||
}); | ||
}); | ||
|
||
describe('strictKeywords = "log"', function() { | ||
it('should log a warning given an unknown keyword in the schema root when strictKeywords is "log"', function() { | ||
var output = {}; | ||
var ajv = new Ajv({ | ||
strictKeywords: 'log', | ||
logger: getLogger(output) | ||
}); | ||
var schema = { | ||
properties: {}, | ||
unknownKeyword: 1 | ||
}; | ||
ajv.compile(schema); | ||
should.equal(output.warning, 'unknown keyword: unknownKeyword'); | ||
}); | ||
}); | ||
|
||
|
||
function getLogger(output) { | ||
return { | ||
log: function() { | ||
throw new Error('log should not be called'); | ||
}, | ||
warn: function(warning) { | ||
output.warning = warning; | ||
}, | ||
error: function() { | ||
throw new Error('error should not be called'); | ||
} | ||
}; | ||
} | ||
}); |