I have a custom test, but when its implemented inside a schema, it stops the whole schema, even I already have abortEarly: true for the schema itself.
I defined the test like this:
const dateFormatRequired = () => yup
.string()
.test({
name: 'date-format-bd',
message:'Date format should be MM/DD/YYY',
test: (value, cotext) => {
console.log(value)
const dateInList = value.split('-');
const yearHasCorrectDigit = dateInList[0].length === 4;
const monthAndDayHasCorrectDigit = dateInList[1].length == 2 && dateInList[2].length == 2;
return yearHasCorrectDigit && monthAndDayHasCorrectDigit;
},
params: {
abortEarly: false
}
})
Schema itself like this:
const schema = yup.object().shape({
dateOfBirth: dateFormatRequired(),
gender: isRequiredOnly,
);
schema
.validateSync({...some values match my data shape}, { abortEarly: false })
When the dateFormatRequired failed, the whole schema's error.inner will be empty.
Any suggestions how can I debug this further or a solution?