elliotforwater.com
elliotforwater.com copied to clipboard
Remove Enzyme from tests
I finally manage to fix all the dependencies to React 17.0.2 so we should be ok with waiting a couple of weeks before upgrading to react 18. In order to upgrade to React 18 we need to get rid of Enzyme test utility. We are already using React Testing library for most of the tests Therefore we need to change some test case from Enzyme to react testing library.
Goal:
- remove Enzyme library
- write all the tests with React testing library
Please check in each test file where Enzyme is still used. Here is a list of the test file I found so far that still include Enzyme: AllResultsView Footer SubscribeForm ImagesView ButtonPrimary Header Hero Map NewsView SearchBar Toast Tooltip app
For any questions, feel free to ask me
@karlrez I think you need to comment this issue so I can assign it to you
@gsambrotta ok, lets see if you can assign me now
Yepp! I manage now :) Thank you Karl
Hey @gsambrotta, a couple questions on this. I see the "should render without throwing an error" test is repeated many times in the project with the same type of test, so I want your thoughts on how I should approach these.
For example in Footer.test.tsx:

- Would approach 1 work for you? As it does not exactly replicate the existing enzyme test.
- I like approach 3 best, but it requires adding
@testing-library/jest-domto the project. Do you see any issues with adding that package?
I also find the jest-dom package can be useful for the tests with images, as the toHaveAttribute() method will work to check the src of the image.
Hi @karlrez! I think the different approaches are quite similar. Yes, they do not replicate the existing enzyme test but that is expected because the two libraries have quite different approaches to testing.
To me seems that the 3 approaches you wrote are very similar in logic, just the way how you write the code is slightly different.
Personally, I like better approach n.2 because to me is easier to read (in "english style")
Anyway, we can totally add jest-dom if needed. We will for sure need it also for other test in the future, so no problem on that