From the course: Building Modern Projects with React
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Testing selectors - React.js Tutorial
From the course: Building Modern Projects with React
Testing selectors
- [Instructor] All right, so now that we've seen how to test reducers, let's take a look at how to test selectors. The good news here (laughing) is that testing selectors is probably one of the easiest things to test. It's in fact so easy that this could probably be used to teach test-driven development in the (laughing) first place, right? So with selectors, all you really have to do is come up with a realistic starting value for the state and make sure that the value returned by the selector is what you would expect it to be, right? So again, this is very straightforward. All we're going to do is create a new file inside Source. We'll call this selectors.test.js. And now I'll just demonstrate this, you know what? I'll demonstrate this on getCompletedTodos, just to give you something a little bit more complicated here, we'll say import getCompletedTodos. And then, and here, this is going to need to be ,js here, just so that we can run it with the node script. Then we're just going to…