OK, first although testing your routing code is something you may or may not want to do, in general, try to separate your interesting business logic in pure javascript code (classes or functions) that are decoupled from express or whatever framework you are using and use vanilla mocha tests to test that. Once you ve achieved that if you want to really test the routes you configure in mocha, you need to pass mock req, res
parameters into your middleware functions to mimic the interface between express/connect and your middleware.
简而言之,您可创设一个模拟模型res
,标有render/code>功能,看上类似情况。
describe routes , ->
describe #show_create_user_screen , ->
it should be a function , ->
routes.show_create_user_screen.should.be.a.function
it should return something cool , ->
mockReq = null
mockRes =
render: (viewName) ->
viewName.should.exist
viewName.should.match /createuser/
routes.show_create_user_screen(mockReq, mockRes).should.be.an.object
而且,光辉电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层,电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层电离层。
正如你在评论中要求的那样,这里是 Java。
describe( routes , function() {
describe( #show_create_user_screen , function() {
it( should be a function , function() {
routes.show_create_user_screen.should.be.a["function"];
});
it( should return something cool , function() {
var mockReq = null;
var mockRes = {
render: function(viewName) {
viewName.should.exist;
viewName.should.match(/createuser/);
}
};
routes.show_create_user_screen(mockReq, mockRes);
});
});
});