When adding a string parameter to required() ex. 'required("Required")' for yup.date the parameter is not added to the validation object when validate() is ran.
expected: Required
actual: effectiveDate must be a date type, but the final value was: Invalid Date (cast from the value "").
Yup Object used
export const = DateSchema = Yup.object().shape({
date : Yup.object().shape({
effectiveDate: Yup.date().required("Required"),
expirationDate: Yup.string().required('Required'),
})
})
Also expirationDate's error message in the validation object shows "Requred" as expected.
The issue is resolved. I needed to add .nullable().
Yup.date().required("Required").nullable().
Most helpful comment
The issue is resolved. I needed to add .nullable().
Yup.date().required("Required").nullable().