DEV Community

Cover image for Testing a React App with React Testing Library
Lucas Q
Lucas Q

Posted on

Testing a React App with React Testing Library

A step by step guide on how to test a React App (made in Next.js in this case) with React Testing Library.

I created a very simple Next.js app to demonstrate how to test the whole functionality of it and approach different blockers when writing unit tests.

In this post I cover:

  • Testing component’s behavior and emulating user events to assess for the expected result.
  • Mocking API calls with msw library.
  • Mocking custom and node_modules components imports in case they should not be included in our tests.
  • Accessing to env variables in our tests.
  • Troubleshooting some common errors we discovered while testing.

Link to the blogpost

Hope you enjoy it! If you have any doubts you can reach me at
LinkedIn

Top comments (0)