From the course: JavaScript: Test-Driven Development (ES6)
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Testing a server's error path - JavaScript Tutorial
From the course: JavaScript: Test-Driven Development (ES6)
Testing a server's error path
- [Instructor] So now we've tested what's called the happy path of our server endpoint. The case where everything goes as expected and there's a user in our database with the username specified in the URL. But as you can imagine, in the real world, this is only one of several possible situations that our app will experience. What if an error occurs while communicating with the database, for example, if our server can't make a connection? Well, in this case, we'd want the response that we send to the front end to be different. We'd want a response to have a 500 status code instead of 200, and in the body we'd want to send a message with more information about what went wrong. So let's write a test for this situation. Let's go down to the bottom of our server.test file and add another test. And for this one, we're going to say that it sends the correct response when there is an error. And this is going to be an async test…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.