Member-only story

Everything You Need to Get Started With Testing in React

A gentle introduction for beginners

Mohammad Faisal
Better Programming
4 min readFeb 25, 2021

--

A calligraphy pen resting on an empty notebook.
Photo by Aaron Burden on Unsplash

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.

When you create a project with create-react-app, the testing setup is automatically there for you. Otherwise, refer to this.

Viewing your new project in the src folder.
New project

2. Our First Test

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

--

--

Responses (1)

Write a response