Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!