-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
allRequired.spec.js
47 lines (41 loc) · 1.23 KB
/
allRequired.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');
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 });
});
});
});
});