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
From the course: Building React and Django Apps
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Unit testing a component1m 44s
-
(Locked)
Unit testing two React routes and navigation between components2m 15s
-
(Locked)
End2End testing the form submission process1m 30s
-
(Locked)
End2End testing the filtered data table48s
-
(Locked)
Unit testing caching with Django REST framework50s
-
(Locked)
Unit testing sorting and filtering1m 37s
-
(Locked)
Unit testing validation for the REST API59s
-
(Locked)
-