Tyler Gillies
Tyler Gillies

Reputation: 1907

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!

Upvotes: 4

Views: 2581

Answers (2)

dgo.a
dgo.a

Reputation: 2764

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

Upvotes: 2

Russ Bradberry
Russ Bradberry

Reputation: 10865

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'
    }
});

Upvotes: 3

Related Questions