How to Test React Components Using Jest

A repository written for a blog post about testing React with Jest.

Requirements

Running locally

  • git clone this repo
  • cd testing-react-with-jest
  • npm install
  • In one tab, run npm run watch. This will fire up Webpack and rebuild your app on each change.
  • In another tab, run npm start. This will fire up a local server that will refresh automatically when the code changes.
  • open http://localhost:8081 to view to the app.

Tests

Run npm test to run the tests with Jest.

Run npm test -- --watch to run Jest and have it automatically rerun everytime you change a file.

Problems / Questions

Please feel free to raise an issue if you have any Qs :)

License

The MIT License (MIT)

Copyright (c) 2020 SitePoint

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.