Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
yup .test validation prevent other rules from execution in the schema

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!