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?