Skip to content
helper library for testing express applications
JavaScript Shell
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
bin
lib
test/lib
.gitignore
.travis.yml
README.md
index.js
package.json

README.md

build status

express-test

This package allows you to test express routes without opening http requests or going through app middleware. It makes it easy to build a request for your route and verify the response.

example

// routes/hello.js

module.exports = function(app) {
  app.get('/hello', function(req, res) {
    res.send('hello');
  });
};
// test/routes/hello-test.js

// create server
var express = require('express'),
    should = require('should');
require('express-test');

var app = express.createServer();

// require the route you're going to test
require('./routes/hello')(app);

// test the body
app.request().get('/hello').end()
.verify(function(res) {
  res.body.should.equal('hello');
});

// set sinon expectations on the response mock
app.request().get('/hello').end(function(res) {
  res.expects('send').once();
}).verify();
Something went wrong with that request. Please try again.