I see alot of examples on how to test the api responses, but nothing about testing the actual router itself (if abstracted into separate files).
I'm trying to test that my express app routes are directed to the correct controller methods.
For example -
//server.js, base application
var express = require("express");
var app = express();
require("./routes.js")(app);
...
//routes.js
var menuController = require("./controllers/menu.js");
module.exports = function(expressApp) {
expressApp.get('/menu', menuController.getMenu);
};
...
//test file
var express = require('express')
, menuController = require("../../controllers/menu.js")
, chai = require('chai')
, should = chai.should()
, sinon = require('sinon')
, sinonChai = require("sinon-chai");
chai.use(sinonChai);
var app = express();
require("../../routes/routes.js")(app);
describe('routes.js', function(){
it('/menu should call menuController.getMenu route', function(){
var spy = sinon.spy(menuController, 'getMenu');
app.get('/menu', spy);
spy.should.have.been.called; //fails, never called
});
});
How can I check to see that when calling app.get('/menu', ..), the callback from menuController is invoked? Should I restructure the app somehow (I see a bunch of other ways to configure the routing)?
--
You received this message because you are subscribed to the Google Groups "Express" group.
To unsubscribe from this group and stop receiving emails from it, send an email to express-js+...@googlegroups.com.
To post to this group, send email to expre...@googlegroups.com.
Visit this group at http://groups.google.com/group/express-js.
For more options, visit https://groups.google.com/d/optout.