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

Unit testing a component

From the course: Building React and Django Apps

Start my 1-month free trial

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…

Contents