Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda