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 a component
From the course: Building React and Django Apps
Unit testing a component
- Now we're going to unit test the filters component using jest. Make sure you import, render, clean up and fire event from testing library. These are core tools for testing reactive components. After each test we're going to call clean up. Which will clean up the dom and unmount the react component. Our unit test will be asynchronous, because we're testing a call back. In the call back, we will ensure that the state changes. Then we call done, to let jest know that the test has finished running. We can use render to mount the component into the dom. We pass in our call back here. Now we check that the rendering of the component has worked. By querying for the price label. Then we query by place holder text for the minimum price field. We expect that the field will start off empty. After checking the initial state we fire a change event. That changes the minimum price field. And we confirm that the field has indeed…
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)
-