Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Enzyme from tests #173

Open
gsambrotta opened this issue Aug 1, 2022 · 5 comments · May be fixed by #177
Open

Remove Enzyme from tests #173

gsambrotta opened this issue Aug 1, 2022 · 5 comments · May be fixed by #177
Assignees

Comments

@gsambrotta
Copy link
Collaborator

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

@gsambrotta
Copy link
Collaborator Author

@karlrez I think you need to comment this issue so I can assign it to you

@karlrez
Copy link
Contributor

karlrez commented Aug 1, 2022

@gsambrotta ok, lets see if you can assign me now

@gsambrotta
Copy link
Collaborator Author

Yepp! I manage now :) Thank you Karl

@karlrez
Copy link
Contributor

karlrez commented Aug 5, 2022

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:
image

  • 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-dom to 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.

@gsambrotta
Copy link
Collaborator Author

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

@karlrez karlrez linked a pull request Aug 17, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants