From the course: Node.js: Testing and Code Quality

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Test doubles and Express apps

Test doubles and Express apps

- [Instructor] Let's write some functional tests using an express app. There are a few steps necessary to do this. If you want to take a look at a reference or just copy the file, it can be found in the exercise files. When you're ready, switch over to VS code. We're going to be functionally testing reservations. So in the Explorer, navigate to the Route folder. Right click and select New file. We'll be testing the reservations route, so this will be named reservations.test.js. We'll start off by requiring SuperTest which we'll use for HTTP assertions. So const request equals require SuperTest. We'll create a placeholder for the app itself, which will be wrapped with SuperTest in a before all. So let app, and then a semi-colon. We also want to silence Morgan, the HTTP requests logger, so it doesn't clutter our test output with log messages. So we use const mock Morgan is a jest function which is an express middleware,…

Contents