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

113
Visualizações
Function behaves differently in Jest than it does in the app

I am trying to test a simple function in Jest that compares 2 strings. If they are equal the function should return true. If not it should return false.

It looks like this:

export const validateInput = (dispatch) => {
  return (userInput, expected) => {
  if (userInput === expected) {
      navigate('done')
      return true
  }
  else{
    dispatch({ type: 'error_message', payload: 'your seed phrase was not typed correctly'})
    return false
    }
  }
}

When I use it in Jest like this:

it('gives valid and invalid input to validateInputPhrase', () => {
        const userInput = 'blouse'
        const expected = 'hello'
        expect(validateInput(userInput, expected)).toBeTruthy()
        expect(validateInput(userInput, 'blouse')).toBeTruthy()
    })

Jest is saying that in both cases it is truthy, even though 'blouse' is clearly not equal to 'hello'.

Does anyone see the problem here and why the function validateInput always resolves to truthy in the test?

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