Skip to content
Myr

middleware.basic.js

This file

Path

test/middleware.basic.js

41 lines · 1.0 KiB · JavaScript

Last changed by

tests: assert calls order in middleware basic tests김정환before adoption8a97346

History of this file

Take it

The walk stopped after 200 commits: lines older than 5cc761c point at it.

deps: parseurl@~1.3.2Douglas Christopher Wilsonbefore adoption5cc761c

line 1why, one step back
1

tests: assert calls order in middleware basic tests김정환before adoption8a97346

line 2why, one step back
2var assert = require('assert')

deps: parseurl@~1.3.2Douglas Christopher Wilsonbefore adoption5cc761c

lines 3–31why, one step back
3var express = require('../');
4var request = require('supertest');56describe('middleware', function(){7 describe('.next()', function(){8 it('should behave like connect', function(done){9 var app = express()10 , calls = [];1112 app.use(function(req, res, next){13 calls.push('one');14 next();15 });1617 app.use(function(req, res, next){18 calls.push('two');19 next();20 });2122 app.use(function(req, res){23 var buf = '';24 res.setHeader('Content-Type', 'application/json');25 req.setEncoding('utf8');26 req.on('data', function(chunk){ buf += chunk });27 req.on('end', function(){28 res.end(buf);29 });30 });31

tests: run mocha with --no-exit to detect hangsDouglas Christopher Wilsonbefore adoptionde129c2

line 32why, one step back
32 request(app)

deps: parseurl@~1.3.2Douglas Christopher Wilsonbefore adoption5cc761c

lines 33–36why, one step back
33 .get('/')
34 .set('Content-Type', 'application/json')35 .send('{"foo":"bar"}')36 .expect('Content-Type', 'application/json')

tests: assert calls order in middleware basic tests김정환before adoption8a97346

line 37why, one step back
37 .expect(function () { assert.deepEqual(calls, ['one', 'two']) })

deps: parseurl@~1.3.2Douglas Christopher Wilsonbefore adoption5cc761c

lines 38–41why, one step back
38 .expect(200, '{"foo":"bar"}', done)
39 })40 })41})