简体   繁体   中英

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 example?

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."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM