我希望以下内容打印错误:
var joi = require('joi');
var schema = {
role_type: joi.string(),
info: {
address: joi.object({
postal_code: joi.string(),
country: joi.string().uppercase().length(2)
})
.when('role_type', {
is: 'org', // When role_type is "org" the address props become required
then: {
postal_code: joi.required(),
country: joi.required()
}
})
}
};
var data = {
role_type: 'org',
info: {address: {country: 'AF'}}
};
joi.assert(data, schema);
不幸的是,上面的代码没有产生任何错误。为什么?
在 joi v6 和最新的 v10 上测试。