From the course: Building React and Django Apps

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Unit testing two React routes and navigation between components

Unit testing two React routes and navigation between components

From the course: Building React and Django Apps

Start my 1-month free trial

Unit testing two React routes and navigation between components

- [Instructor] Now, let's use a unit test to confirm that navigation in our app is working correctly with react router. Before we write the test, notice that we have provided mock data in functions using jest. These mock at the service API HTTP responses. Now let's begin writing the test. It will be an async test, and we start by rendering the component, and then we use the wait function to wait until it is fully rendered in the dom, so that all the data that is loaded from service API is displayed. The testing library for react provides several utilities such as render, fire event, cleanup, and wait. These make it very simple to write unit tests using jest for react. We've seen cleanup, render, and fire event before, and in this unit test, we're using wait. Back to the unit test. Now we check that the service API's method has been called and we make sure that some data has loaded. Then we fire a click event to…

Contents