title: How to unit test express Router routes
body: <p>I'm new to Node and Express and I'm trying to unit test my routes/controllers. I've separated my routes from my controllers. How do I go about testing my routes?</p>
  
  <p><strong>config/express.js</strong></p>
  
  <pre><code>  var app = express();
    // middleware, etc
    var router = require('../app/router')(app);
  </code></pre>
  
  <p><strong>app/router/index.js</strong></p>
  
  <pre><code>  module.exports = function(app) {
      app.use('/api/books', require('./routes/books'));
    };
  </code></pre>
  
  <p><strong>app/router/routes/books.js</strong></p>
  
  <pre><code>  var controller = require('../../api/controllers/books');
    var express = require('express');
    var router = express.Router();
  
    router.get('/', controller.index);
  
    module.exports = router;
  </code></pre>
  
  <p><strong>app/api/controllers/books.js</strong></p>
  
  <pre><code>// this is just an example controller
  exports.index = function(req, res) {
      return res.status(200).json('ok');
  };
  </code></pre>
  
  <p><strong>app/tests/api/routes/books.test.js</strong></p>
  
  <pre><code>  var chai = require('chai');
    var should = chai.should();
    var sinon = require('sinon');
  
    describe('BookRoute', function() {
  
    });
  </code></pre>