Skip to content
Myr

test: add discarded middleware test (#5819)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Chris de Almeida · committed by GitHub · parent 94546a3 · Browse files · 1 file+50 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+50 added−0 removed

  • tests:+50 added−0 removed

1 file+50 added−0 removed

modified:test/app.router.js+50 added
1154 unmodified lines
1155 it('should be chainable', function(){1156 var app = express();1157 assert.strictEqual(app.get('/', function () {}), app)1158 })11591160 it('should should not use disposed router/middleware', function(done){1161 // more context: https://github.com/expressjs/express/issues/5743#issuecomment-227714841211621163 var app = express();1164 var router = new express.Router();11651166 router.use(function(req, res, next){1167 res.setHeader('old', 'foo');1168 next();1169 });11701171 app.use(function (req, res, next) {1172 return router.handle(req, res, next);1173 });11741175 app.get('/', function(req, res, next){1176 res.send('yee');1177 next();1178 });11791180 request(app)1181 .get('/')1182 .expect('old', 'foo')1183 .expect(function(res) {1184 if (typeof res.headers['new'] !== 'undefined') {1185 throw new Error('`new` header should not be present');1186 }1187 })1188 .expect(200, 'yee', function(err, res) {1189 if (err) return done(err);11901191 router = new express.Router();11921193 router.use(function(req, res, next){1194 res.setHeader('new', 'bar');1195 next();1196 });11971198 request(app)1199 .get('/')1200 .expect('new', 'bar')1201 .expect(function(res) {1202 if (typeof res.headers['old'] !== 'undefined') {1203 throw new Error('`old` header should not be present');1204 }1205 })1206 .expect(200, 'yee', done);1207 });1208 })1209})12101211function supportsRegexp(source) {1212 try {
6 unmodified lines