1. 31
    A Comprehensive Example of Testing Redux Connected React Components
    1m 37s

A Comprehensive Example of Testing Redux Connected React Components

Jamund Ferguson
InstructorJamund Ferguson
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 3 years ago

For this lesson we combine a number of techniques we've learned already. Those include getAllByRole(), using jest spies, getByRole with a filter on the accessible name, and waitFor.

Instructor: Open up your IDE and start jest in watch mode. Then make sure to import wait for from testing library/react. Now at the bottom of your test, add a new one called should clear items after checkout.

This one, we'll start by setting up our checkout spy to mock the result value once of success true. The rest of the setup for this test, we're going to grab from the removed items tests, including confirming that the cart has a total of $71 with its carrots and bunnies.

We're also going to confirm the number of rows by typing expect screen.getAll by roll row to have length four. Now type const checkout = screen.get by roll button, the name of checkout, and user event.click checkout. Now for the key part of this test.

Await, wait for, pass in our function. Make sure we have an async function. Then in our wait for callback here, we're going to wait for the total text to be zero and for the table to have only two rows. We can also expect that screen.get by roll table is not going to have class checkout error.

We started off here four rows with a total of $71. We clicked checkout and waited until the table was empty and there were only two rows, the header and the footer. We also have noted that there's no errors.

This all relies on us using checkout spy.mock result value once to ensure that our checkout was a success without actually having to hit the network.

egghead
egghead
~ 46 seconds ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today