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

224
Visualizações
Jest Unit Testing - how to unit test if/else condition and call method based on true/false inside jest?

I started learning Jest framework. Would like to write test case for following method

const valueCheck() =  () => {
if (typeof (props.user.value != undefined) && props.user.value){
    callResult([]);
} else{
   notification.warn(['Wrong value']);
 }
}

Not sure how to do that. Please help I am not able to figure this out

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

you need to test if callResult() or a notification.warn was called when you call valueCheck()

To do this you must use a spy function for valueCheck and notification

Also ,our syntax is incorrect and it can be simplified in a one line arrow function:

const valueCheck = () => props?.user?.value ? callResult() : notification.warn(['Wrong value'])
about 4 years ago · Santiago Gelvez Relatório
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