Skip to content

Commit

Permalink
✅ add discarded middleware test
Browse files Browse the repository at this point in the history
  • Loading branch information
ctcpip committed Sep 10, 2024
1 parent 21df421 commit 5b4b03e
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/app.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,54 @@ describe('app.router', function(){
var app = express();
assert.strictEqual(app.get('/', function () {}), app)
})

it('should should not use disposed router/middleware', function(done){
var app = express();
var router = new express.Router();

router.use(function(req, res, next){
res.setHeader('old', 'foo');
next();
});

app.use(function (req, res, next) {
return router.handle(req, res, next);
});

app.get('/', function(req, res, next){
res.send('yee');
next();
});

request(app)
.get('/')
.expect('old', 'foo')
.expect(function(res) {
if (typeof res.headers['new'] !== 'undefined') {
throw new Error('`new` header should not be present');
}
})
.expect(200, 'yee', function(err, res) {
if (err) return done(err);

router = new express.Router();

router.use(function(req, res, next){
res.setHeader('new', 'bar');
next();
});

request(app)
.get('/')
.expect('new', 'bar')
.expect(function(res) {
if (typeof res.headers['old'] !== 'undefined') {
throw new Error('`old` header should not be present');
}
})
.expect(200, 'yee', done);
});
})
})

function supportsRegexp(source) {
Expand Down

0 comments on commit 5b4b03e

Please sign in to comment.