-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
var Joi = require('joi');
var T = Joi.types;
var schema = {
accepted_payments: T.Array().includes(T.String().valid('amex','visa'))
};
var err1 = Joi.validate({ accepted_payments: ['amex'] }, schema);
var err2 = Joi.validate({ accepted_payments: ['visa','mc'] }, schema);
console.log(err1);
console.log(err2);
err2 should have an error since mc is not a valid value for the strings defined inside includes().
Looking through array.js, it looks like there are explicit tests for include() when validation modifiers are used that ultimately call BaseType.prototype.add (like String().regexp() or Number().integer()), but none when using valid() or allow().
In other words, the following behaves as expected:
var Joi = require('joi');
var T = Joi.types;
var schema = {
emails: T.Array().includes(T.String().email())
};
var err1 = Joi.validate({ emails: ['a@b.com'] }, schema);
var err2 = Joi.validate({ emails: ['a@b.com','foobar'] }, schema);
console.log(err1);
console.log(err2); // contains error since `foobar` isn't a valid email.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugBug or defectBug or defect