sábado, 23 de abril de 2016

My new pet-project a tester for express routes

Some time ago I started a little pet-poject for learning node, express, ... I found an problem because I cannot test the routes of my express api.

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