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

124
Visualizações
How to perform two test on same yup field where one test uses async await

The validation is working for required and imageHeight but not for fileFormat. I am using async await to wait till the time image loads and return exact height.

Array of supported formats

const SUPPORTED_FORMATS = [
  "image/jpg",
  "image/jpeg",
  "image/png",
];

Function to get image height


const getImageHeight = (value) => {
  return new Promise((resolve, reject) => {
    let img = new Image();
    img.onload = () => resolve(img.height);
    img.onerror = reject;
    img.src = value?.data || value;
  });
};

Yup validation

export const ImageValidate = Yup.object({
  image: Yup.mixed()
    .required("Please select image")
    .test("fileFormat", "Unsupported Format", (value) => {
      return SUPPORTED_FORMATS.some((type) =>
         type === value?.file?.type
      );
    })
    .test(
      "imageHeight",
      "image height should be >=100",
      async (value) => {
        if (value) {
          const dimension = await getImageHeight(value);
          if (dimension.height >=100) {
            return true;
          }
          return false;
        }
        return false;
      }
    ),
});
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