开发者

nodejs/express testing

I'm writing an app with express.

The main file is called server.js

one of the objects is

var app = express.createServer(express.logger(),
    express.bodyDecoder());

then I have

app.get("/",function(req, res){
  res.send("Running");
}

How do I use expresso, [or any other testing framework for that matter], to test the routes output?

I looked at the expresso site, but couldn't figure out how to get it to all work together, is it possible if someone gave me a short examp开发者_高级运维le?

Thanks!


I'm sure you have found the answer to this by now but have you tried something like this:

assert.response(server, {
    url: '/',
    method: 'GET'
},{
    body: '{"name":"tj"}',
    status: 200,
    headers: {
        'Content-Type': 'application/json; charset=utf8',
        'X-Foo': 'bar'
    }
});


If you're new to Node.js and getting confused with all the different testing libs:

Expresso's successor is Mocha. In Mocha, you use a separate tool for HTTP response testing, such as Request, SuperTest, zombie.js, etc.

Zombie.js seems the easiest to learn how to use, esp. w/ cookies and cookie-based sessions. It "maintains state across requests: history, cookies, HTML5 local and session stroage, etc."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜