Transcript

Kent C. Dodds: 0:00 As we make changes to our code, we want to make sure that we didn't break anything and so we're going to test it to ensure that we have confidence in shipping the code that we've changed.

0:10 That would take too long to do manually, so we're going to automate that process using a testing framework called Jest. Jest is built into create-react-app which we're using, or you can install it separately. Either way, Jest is a fantastic library for unit, integration, and component testing, and I love using it for my projects.

0:30 Here, I give you a tiny bit of background on a unit test. I give you a link to a blog post. My blog is super-duper full of testing content, so feel free to spend a lot of time over there reading about anything around testing.

0:45 For our exercise, we're going to be testing two things -- the formatDate() function, which will be quick and easy. It's a pure function. It doesn't do a whole lot. Then, we'll be testing the client, which is not quick, not easy. It is a little bit more complicated.

1:00 We're going to be mocking out the fetch calls that it's making with MSW, which is an amazing tool for doing this kind of testing.

1:09 I'll give you a little example of how you can use MSW in your test, and you can feel free to take a look at the docs as well. Here are the files that we're going to be working in, and then we also do have some extra credit to enhance our test for that client and improve the setup for all of our tests as well.

1:26 To get things running, you can simply run npm t, and that will get our test going in watch mode. We've got a couple of tests for you to do. Dive in and we'll see you on the other side of the exercise.