UNPKG

jaywalk

Version:
62 lines 2.24 kB
"use strict"; var test = require('blue-tape'); var index_1 = require('../index'); test('omit', function (t) { t.test('omit value after validation', function (t) { var schema = new index_1.Types.Number({ uses: [ new index_1.Types.Omit() ] }); 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, 'type'); }); }); t.test('valid type but omit value', function (t) { return validate(100) .then(function (value) { t.equal(value, undefined); }); }); }); t.test('omit value from object', function (t) { var schema = new index_1.Types.Object({ properties: { password: new index_1.Types.String({ minLength: 5, maxLength: 100 }), confirmPassword: new index_1.Types.String({ uses: [ new index_1.Types.Omit(), new index_1.Types.Condition({ left: index_1.Utils.ref(['password'], 1), right: index_1.Utils.ref([]) }) ] }) } }); var validate = index_1.compile(schema); t.test('omit value on return', function (t) { return validate({ password: 'hunter2', confirmPassword: 'hunter2' }) .then(function (value) { t.deepEqual(value, { password: 'hunter2' }); }); }); t.test('should error when values mismatch', function (t) { t.plan(2); return validate({ password: 'hunter2', confirmPassword: 'hunter3' }) .catch(function (err) { t.equal(err.errors.length, 1); t.equal(err.errors[0].type, 'Condition'); }); }); }); }); //# sourceMappingURL=omit.spec.js.map