September 2014
Intermediate to advanced
316 pages
7h 6m
English
So far, we have not done any testing. This is bad and not a best practice. We will rectify this here. We will only build a few tests, but it will demonstrate how to create tests. Create a directory named tests and create the routes.js file.
Open the file and paste the following code:
var routes = require('../routes'),
config = require('../config'),
nodeunit = require('nodeunit'),
Request = require('./request'),
Response = require('./response');
exports.indexRouteTest = function(test){
var res = new Response();
test.equal(res.view, undefined);
routes.index({}, res);
test.equal(res.view, 'index');
test.equal(res.viewData.title, 'Index');
test.done();
};Here, we are testing the index route. It should call render on the response object ...