Mocking [Connect] or [Express] middleware in Node.js is easy. Simple create your request
and response
objects and use the next
function as the harness to tests.
I'm going to assume [Tape] for this example, but this is easily ported to [Mocha], [nodeunit] or any other test harness of your choosing.
// file: simple_middleware.js
module.exports = function(request, response, next) {
response.foo = 'foo';