Skip to content

Commit 5b4b03e

Browse files
committed
✅ add discarded middleware test
1 parent 21df421 commit 5b4b03e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/app.router.js

+48
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,54 @@ describe('app.router', function(){
11301130
var app = express();
11311131
assert.strictEqual(app.get('/', function () {}), app)
11321132
})
1133+
1134+
it('should should not use disposed router/middleware', function(done){
1135+
var app = express();
1136+
var router = new express.Router();
1137+
1138+
router.use(function(req, res, next){
1139+
res.setHeader('old', 'foo');
1140+
next();
1141+
});
1142+
1143+
app.use(function (req, res, next) {
1144+
return router.handle(req, res, next);
1145+
});
1146+
1147+
app.get('/', function(req, res, next){
1148+
res.send('yee');
1149+
next();
1150+
});
1151+
1152+
request(app)
1153+
.get('/')
1154+
.expect('old', 'foo')
1155+
.expect(function(res) {
1156+
if (typeof res.headers['new'] !== 'undefined') {
1157+
throw new Error('`new` header should not be present');
1158+
}
1159+
})
1160+
.expect(200, 'yee', function(err, res) {
1161+
if (err) return done(err);
1162+
1163+
router = new express.Router();
1164+
1165+
router.use(function(req, res, next){
1166+
res.setHeader('new', 'bar');
1167+
next();
1168+
});
1169+
1170+
request(app)
1171+
.get('/')
1172+
.expect('new', 'bar')
1173+
.expect(function(res) {
1174+
if (typeof res.headers['old'] !== 'undefined') {
1175+
throw new Error('`old` header should not be present');
1176+
}
1177+
})
1178+
.expect(200, 'yee', done);
1179+
});
1180+
})
11331181
})
11341182

11351183
function supportsRegexp(source) {

0 commit comments

Comments
 (0)