-
-
Notifications
You must be signed in to change notification settings - Fork 17.2k
/
Copy pathmiddleware.basic.js
42 lines (36 loc) · 1.03 KB
/
middleware.basic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict'
var assert = require('node:assert')
var express = require('../');
var request = require('supertest');
describe('middleware', function(){
describe('.next()', function(){
it('should behave like connect', function(done){
var app = express()
, calls = [];
app.use(function(req, res, next){
calls.push('one');
next();
});
app.use(function(req, res, next){
calls.push('two');
next();
});
app.use(function(req, res){
var buf = '';
res.setHeader('Content-Type', 'application/json');
req.setEncoding('utf8');
req.on('data', function(chunk){ buf += chunk });
req.on('end', function(){
res.end(buf);
});
});
request(app)
.get('/')
.set('Content-Type', 'application/json')
.send('{"foo":"bar"}')
.expect('Content-Type', 'application/json')
.expect(function () { assert.deepEqual(calls, ['one', 'two']) })
.expect(200, '{"foo":"bar"}', done)
})
})
})