Skip to content

Instantly share code, notes, and snippets.

@i-van
Created August 6, 2018 10:34
Show Gist options
  • Save i-van/6b8b3c348576cf0b9b762486dd8576bf to your computer and use it in GitHub Desktop.
Save i-van/6b8b3c348576cf0b9b762486dd8576bf to your computer and use it in GitHub Desktop.
import Joi from 'joi';
const schema = Joi.object({
a: Joi.string().required(),
b: Joi.string().required(),
});
const {error: error1} = Joi.validate(null, schema); // "value" must be an object
const {error: error2} = Joi.validate(undefined, schema); // null
const {error: error3} = Joi.validate({}, schema); // child "a" fails because ["a" is required]
const {error: error4} = Joi.validate({a: 'qwerty'}, schema); // child "b" fails because ["b" is required]
const {error: error5} = Joi.validate({a: 'qwerty', b: 'asdfgh'}, schema); // null
console.log('--- 1', error1);
console.log('--- 2', error2);
console.log('--- 3', error3);
console.log('--- 4', error4);
console.log('--- 5', error5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment