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."
精彩评论