Chapter 9. Testing React components

 

This chapter covers

  • Testing front-end applications
  • Setting up testing for React
  • Testing React components
  • Setting up test coverage

In the last chapter, you added some significant functionality to your application. It now has routing and user state, and you’ve broken it up into smaller pieces. You even added some basic authentication so users could log in using their GitHub profile. Your application is starting to look more robust, even if it’s probably not going to worry anyone at Facebook or Twitter. You can do lots more with React than you could when we first started. But as we’ve focused on learning the basics, we’ve omitted an important part of the development process: testing.

I didn’t cover testing from the start to spare you the mental overload of learning React and testing fundamentals at the same time. But that doesn’t mean it’s an unimportant part of either learning or web development. In this chapter, we’ll focus on testing because it’s a fundamental part of developing high-quality software solutions. Instead of demonstrating tests for every single one of your components, though, we’ll go through a representative sample so you’ll understand the important principles at work and be able to write your own tests.

9.1. Types of testing

9.2. Testing React components with Jest, Enzyme, and React-test-renderer

9.3. Writing your first tests

9.4. Summary