My schema is:
const scenerioSchema = Joi.object({
drawingNode: Joi.object({
moduleRackOutputs: Joi.array()
.items(
Joi.object({
moduleId: Joi.string().required()
})
)
.unique((a, b) => a.moduleId !== b.moduleId)
})
})
My data is:
const mockScenario1 = {
drawingNode: {
moduleRackOutputs: [
{
moduleId: 'module1'
},
{
moduleId: 'module2'
}
]
}
}
When I validate with:
const validationResponse = scenerioSchema.validate(mockScenario1)
I get:
{
validationResponse: {
value: { drawingNode: [Object] },
error: [Error [ValidationError]: "drawingNode.moduleRackOutputs[1]" contains a duplicate value] {
_original: [Object],
details: [Array]
}
}
}
But (a) that's not true - the items are not duplicates and (b) I want an error to occur if the moduleId
is different.
What am I doing wrong?
!==
to===
in the unique function – Rao