Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda