次のエラーが出力されることを期待しています。
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 の両方でテスト済み。