Skip to content
Advertisement

Tag: enzyme

Jest tests keep failing for React component that renders various HTML elements based on type by using switch statement

I have a React Component that takes an array and iterates over each node, styling and rendering HTML elements based on the types found within the array. I have everything running properly and now I’m trying to write a test using Jest to check that: The component doesn’t render anything when it receives an empty array The component renders the

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: So why does the test fail? Answer The problem was that

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 gets transpiled, as you can see

Advertisement