Setting up tests
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 ...
Get Building Scalable Apps with Redis 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.