Loading
Current section: HTTP Mocking 5 exercises
Problem

Testing Error Handling in GitHub API Interceptor

Loading exercise

Transcript

00:00 The way we've got this written is that any time anybody asks us for any access token, we will gladly create a new GitHub user for them and return an access token. So, it's not exactly the way that the GitHub API actually works, but it works really well for our local development.

00:18 So, the trick is, we do have logic for what happens if we can't get an access token, if there's some sort of problem there, like maybe GitHub is down, or the code that was provided is invalid, or something like that. And so, we want to test that logic to make sure that never breaks,

00:35 but our HTTP interceptor handler here is actually not coded in a way that lets us test that. So, we kind of need to override that for this particular test, and there's a way to do that. So, if we come over to our test, you're going to be writing a server.use,

00:55 which will allow us to override a particular handler for this particular test, so that we can make sure that our logic for handling those errors is correct, and what we would expect what we want it to be. So, this is going to require that we export our server and make it accessible,

01:14 which is exactly what we are doing right here. So, you need to import this server, and then add a server.use, but we want to make sure we clean up after ourselves as well, and so you're going to be handling that too. So, a couple of things to do on this one. Have a good time.