-
-
Notifications
You must be signed in to change notification settings - Fork 22.3k
✅ add discarded middleware test #5819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1130,6 +1130,56 @@ describe('app.router', function(){ | |
| var app = express(); | ||
| assert.strictEqual(app.get('/', function () {}), app) | ||
| }) | ||
|
|
||
| it('should should not use disposed router/middleware', function(done){ | ||
| // more context: https://github.com/expressjs/express/issues/5743#issuecomment-2277148412 | ||
|
|
||
| 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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To demonstrate the issue I am trying to address, replace Is there a mechanism in this case to remove the console.log(...)? |
||
| }); | ||
|
|
||
| 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(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't want to replace the router, I want to completely remove it. |
||
|
|
||
| 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) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.