Member-only story
Everything You Need to Get Started With Testing in React
A gentle introduction for beginners
For a long time, like all other self-proclaimed rock-star programmers, I ignored testing. Maybe that’s because it seemed pointless at the beginning. Maybe I was afraid of it. And I know many of you are just like me!
Don’t worry — React has an awesome library named react-testing-library
that’s made testing React components very easy and intuitive. It’s also the recommended way of testing in React.
Today we’ll explore that. Let’s get started!
1. Create New Project
First, scaffold a new React application with create-react-app
.
npx create-react-app learn-testing
When you create a project with create-react-app
, the testing setup is automatically there for you. Otherwise, refer to this.

2. Our First Test
Open your App.test.js
file, and just add the following code to render the App
component.