Skip to content
Advertisement

Unit test with react hook fails

I don’t understand the result I get on this unit test. I expect the second check for textField.valid to be true and instead it returns false.

Below is part of the component I’m testing against:

JavaScript

JavaScript

Below is the test I’m running:

JavaScript

The output of console.log(wrapper.debug()) is the following:

JavaScript

So why does the test fail?

Advertisement

Answer

The problem was that I needed to change the declaration to let textField = wrapper.findWhere((el) => el.type() === TextField && el.props().id === 'name') and then redeclare textField

textField = wrapper.findWhere((el) => el.type() === TextField && el.props().id === 'name')

to update the value in the DOM

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement