Skip to content

Tag: enzyme

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: … Below is the test I’m running: The output of console.log(wrapper.debug()) is the following…

How to mock/spy useState hook in jest?

I am trying to spy on useState React hook but i always get the test failed This is my React component: counter.test.js: Unfortunately this doesn’t work and i get the test failed with that message: Answer You need to use React.useState instead of the single import useState. I think is about how the code …