There are solutions like frisbyjs but I needed only test my routes, not the hole application calling the rest api. So I've write a little library for it.
Here is the code it's a little baby ;-)
Some tests examples
the configuration of the server
var express = require('express'); var app = express(); app.put('/users', function(req, res){ res.send('Users'); }); app.get('/users/:id', function(req, res){ res.send('Users --> id'); }); app.delete('/users', function(req, res){ res.send('Users --> id'); }); module.exports = app;and the tests
var config = require('./expressRouteTest'); var server = require('./server'); config(server) .withVerb('put') .forUrl('/users'); config(server) .withVerb('get') .forUrl('/users/:id'); config(server) .withVerb('delete') .forUrl('/users');