Workshop learning about real-world-like React tests with Jest and RTL.
This project was bootstrapped with Create React App.
git clone https://github.com/JoshuaKGoldberg/unit-testing-react-with-rtl
cd unit-testing-react-with-rtl
npm i
npm start
In the project directory, you can run:
npm start
Runs the app in the development mode. Open http://localhost:3000 to view it in your browser.
The page will reload when you make changes. You may also see any lint errors in the console.
npm test
Launches the test runner in the interactive watch mode. See the section about running tests for more information.
- Tip: use
npm test --watch
to start the test runner in watch mode- Tip: use
npm test filename
to only tests files matching thatfilename
Tests are written using:
src/App.test.js
: Setting up RTL in a Jest testsrc/components/FavoriteStar.test.js
: Using get*
queries to select elementssrc/components/FavoriteStarDelayed.test.js
: Using query*
and find*
queries to select elementssrc/components/Select.test.js
: Using mock functions and simulating user eventssrc/hooks/useLocalStorageItem.test.js
: Mocking out React hooks