From cdab214f59b9749056d6d913efa69ff2499d0492 Mon Sep 17 00:00:00 2001 From: Benjamin Pernick Date: Wed, 5 Aug 2020 20:28:35 -0500 Subject: [PATCH] write test for 'last' magic string of next() function --- test/app.router.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/app.router.js b/test/app.router.js index a6c8cef202a..0f2f23d0b36 100644 --- a/test/app.router.js +++ b/test/app.router.js @@ -957,6 +957,28 @@ describe('app.router', function(){ .expect(200, 'success', done) }) }) + describe('when next("last") is called', function () { + it('should skip to the last piece of middleware', function(done){ + var app = express() + + function fn (req, res, next) { + res.set('X-Hit', '1') + next('last') + } + function badFunc (req, res, next) { + res.end('failure') + } + function lastFunc (req, res, next) { + res.end('success') + } + app.get('/foo', fn, badFunc, badFunc, badFunc, lastFunc) + + request(app) + .get('/foo') + .expect('X-Hit', '1') + .expect(200, 'success', done) + }) + }) describe('when next(err) is called', function(){ it('should break out of app.router', function(done){