O'Reilly logo

Building Scalable Apps with Redis and Node.js by Joshua Johanan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required