DEV Community

Harish G
Harish G

Posted on

Testing in React 17: setup and resources

Image description

A number of times we end up coding in legacy projects, we may face peer dependency errors. I faced one such issues while I started unit testing in a partially developed React project with React v17. Here I share my set up working in legacy environment. I also share some of the popular resources for testing in React.

Setting up testing in React Project with React 17
Create-react-app project comes with jest runner for running tests, but we need to install react-testing-library (RTL)

  • npm config set legacy-peer-deps true (because we use legacy packages)
  • npm install (or npm update)
  • npm i -D @testing-library/react@release-12.x (the latest RTL v13 has no support for React 18)

Resources
https://www.robinwieruch.de/react-testing-library/
https://www.robinwieruch.de/react-testing-jest/

Documentation and recipes
https://testing-library.com/docs/react-testing-library/intro/
https://jestjs.io/docs/tutorial-react

Good practices of -react testing
https://kentcdodds.com/blog/common-mistakes-with-react-testing-library

Some of the example tests
https://github.com/nareshbhatia/react-testing-techniques
https://javascript.plainenglish.io/testing-material-ui-forms-with-react-testing-library-50a9d4d300f2
https://github.com/kentcdodds/testing-react-apps

Tutorial on testing
Bruno Antunes https://youtu.be/41ox41v62jU

Top comments (0)