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
. Since the routes.test.js
file is going to be testing the functionalities of our routes.js
file, we need it to require the same modules. Include the following code in test/server/routes.test.js
:
var home = require('../../controllers/home'),...