...

/

Writing a Component Test without React Testing Library

Writing a Component Test without React Testing Library

Learn how to create a component test without React Testing Library in this lesson.

Creating our first component test

The starter project for this lesson was created by Create React App. Jest is already installed and configured and is ready for us to write a test.

There is a copy of the starter project that you can use in this lesson below:

SKIP_PREFLIGHT_CHECK=true
Starter project code

Open up the src folder in the starter project. We’ll write a test for an ErrorMessage component contained within the folder. The test will check that ErrorMessage renders the correct text for a given message passed into it.

Let’s start by creating a test file in the src/ErrorMessage folder called ErrorMessage.test.js. If you are using the code widget above, this file has already ...