From the course: Building Modern Projects with React

Unlock the full course today

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

Testing selectors

Testing selectors

From the course: Building Modern Projects with React

Start my 1-month free trial

Testing selectors

- [Instructor] And now we move on to testing selectors. I'm happy to announce that in general, selectors are one of the easiest parts of the React ecosystem to test. Just like testing reducers only required us to define an intimal state and an action, testing selectors generally only requires us to define the relevant parts of the state. So testing the base selectors that simply pull something out of the state as is is a bit of a no brainer. I'm not going to spend any time demonstrating it, however, if we on to our slightly more complicated selectors, there are a few tricks to testing them. As an example, let's see how to test our getCompletedTodos selector. Now, the first and most obvious way to test our getCompletedTodos selector would be to simply recreate the whole state and pass it to our getCompletedTodos to test that it returns the right data, and in our case, this would work fine since our state is so small and we…

Contents