middleware.basic.js
This file
Path
test/middleware.basic.js
43 lines · 1.0 KiB · JavaScript
Last changed by
middleware testsTj Holowaychukbefore adoption5b296b5
History of this fileTake it
middleware testsTj Holowaychukbefore adoption5b296b5
lines 1–43why, one step back12var express = require('../')3 , request = require('./support/http');45describe('middleware', function(){6 describe('.next()', function(){7 it('should behave like connect', function(done){8 var app = express()9 , calls = [];1011 app.use(function(req, res, next){12 calls.push('one');13 next();14 });1516 app.use(function(req, res, next){17 calls.push('two');18 next();19 });20 21 app.use(function(req, res){22 var buf = '';23 res.setHeader('Content-Type', 'application/json');24 req.setEncoding('utf8');25 req.on('data', function(chunk){ buf += chunk });26 req.on('end', function(){27 res.end(buf);28 });29 });3031 request(app)32 .get('/')33 .set('Content-Type', 'application/json')34 .write('{"foo":"bar"}')35 .end(function(res){36 res.headers.should.have.property('content-type', 'application/json');37 res.statusCode.should.equal(200);38 res.body.should.equal('{"foo":"bar"}');39 done();40 })41 })42 })43})