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

171
Views
Why yup is trigger my tests even though previous tests are failing?

I want to validate my object with the schema using yup.

But I notice that when I wrote my own test function it's trigger anyway.

I mean I validate the age property for number, null, positive, integer value. then I want to continue with my own logic test.

So I expect to NOT enter the function unless the previous tests are valid.

I'm not sure if this is how it meant to be, but in this way I must also check for valid input in my tests function, even though I add the number, null, positive, integer checks.

So am I using the yup wrong?

What I expect form yup is not invoke the test if the previous tests are invalid.

stackblitz

import { object, string, number, date, InferType } from 'yup';

let userSchema = object({
  age: number()
    .nullable()
    .positive()
    .integer()
    .test({
      message: 'test message',
      test: (v) => {
        console.log('in test!', v);
        return !!v.toPrecision();
      },
    }),
});

userSchema
  .validate({ age: null })
  .then((res) => {
    console.log({ res });
  })
  .catch((e) => {
    console.log({ e });
  });

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!