jaywalk
Version:
Runtime type validation
47 lines • 1.58 kB
JavaScript
;
var test = require('blue-tape');
var index_1 = require('../index');
test('number', function (t) {
t.test('min', function (t) {
var schema = new index_1.Types.Number({
min: 10
});
var validate = index_1.compile(schema);
t.test('should fail with `min`', function (t) {
t.plan(2);
return validate(5)
.catch(function (err) {
t.equal(err.errors.length, 1);
t.deepEqual(err.errors[0].keyword, 'min');
});
});
t.test('should pass with greater than min value', function (t) {
return validate(30);
});
});
t.test('min reference', function (t) {
var schema = new index_1.Types.Object({
properties: {
a: new index_1.Types.Number({
min: 10
}),
b: new index_1.Types.Number({
min: index_1.Utils.ref(['a'], 1)
})
}
});
var validate = index_1.compile(schema);
t.test('should fail with `min` reference', function (t) {
t.plan(2);
return validate({ a: 10, b: 5 })
.catch(function (err) {
t.equal(err.errors.length, 1);
t.deepEqual(err.errors[0].keyword, 'min');
});
});
t.test('should pass with greater than min value', function (t) {
return validate({ a: 10, b: 15 });
});
});
});
//# sourceMappingURL=number.spec.js.map