Testing the application

With all of that background information out of the way, let's focus on writing some real tests for the application we've built. In the following sections, we will write tests for the routes, servers, models, and controllers in our application.

Testing the routes

Let's start things a little slow by taking a look at one of the most basic files in our application, the routes.js file. This file simply defines the number of routes that the application should respond to. This is going to be one of the easiest files to write tests for.

Since the routes.js file is in the server folder within our main application, let's put its corresponding test file in a similar location. Within the tests/server folder, create a file named routes.test.js ...

Get Web Development with MongoDB and Node.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.