UNPKG

jaywalk

Version:
51 lines 1.75 kB
"use strict"; var test = require('blue-tape'); var index_1 = require('../index'); test('string', function (t) { t.test('pattern', function (t) { var schema = new index_1.Types.String({ pattern: '^[a-z]+$' }); var validate = index_1.compile(schema); t.test('fail against invalid pattern', function (t) { t.plan(2); return validate('101') .catch(function (err) { t.equal(err.errors.length, 1); t.deepEqual(err.errors[0].keyword, 'pattern'); }); }); t.test('valid pattern', function (t) { return validate('abc'); }); }); t.test('uses', function (t) { var schema = new index_1.Types.String({ minLength: 10, uses: [ new index_1.Types.Test({ name: 'fail', test: function () { return false; } }) ] }); var validate = index_1.compile(schema); t.test('should fail with `minLength` before `uses`', function (t) { t.plan(2); return validate('hey') .catch(function (err) { t.equal(err.errors.length, 1); t.deepEqual(err.errors[0].keyword, 'minLength'); }); }); t.test('should fail with uses after validation of type', function (t) { t.plan(2); return validate('a longer string to pass validation') .catch(function (err) { t.equal(err.errors.length, 1); t.deepEqual(err.errors[0].keyword, 'test'); }); }); }); }); //# sourceMappingURL=string.spec.js.map