'Joi custom not validating error and always returing undefined

So, it's simple.. I'm trying to do a custom validation and Joi is never failing...

const object = {
  relations: [ 'relationship1.relationship2' ],
  select: null,
};

const schema = Joi.object<any, false, QuerySchema>({
  relations: Joi.array().unique().items(Joi.string()),
  select: Joi.when('relations', {
    is: Joi.array().items(
      Joi.string()
        .custom((value, helper) => {
          if (value.includes('.')) {
            return helper.error('400');
          }
          return true;
        })
        .required(),
    ),
    then: Joi.alternatives(Joi.array().unique().items(Joi.string()), Joi.object()),
    otherwise: Joi.alternatives(Joi.array().unique().items(Joi.string()), Joi.object(), null),
  }),
});

const {error} = schema.validate(object);

and error is always undefined

I've tried with helper.message throw new Error() return true/false

but nothing worked..

Does anyone know what am I doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source