From e32885da5e765860f1c7cd94563d2697ce1679a5 Mon Sep 17 00:00:00 2001 From: Atharv Pandey Date: Thu, 16 Jul 2026 01:28:54 +0530 Subject: [PATCH] Add test coverage for req.is() with array argument The Array.isArray(types) branch at lib/request.js:273 was the only uncovered branch in request.js. Add tests passing an actual array to req.is() to hit that path. Closes #7348 --- test/req.is.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/req.is.js b/test/req.is.js index c5904dd600a..2d113e608ca 100644 --- a/test/req.is.js +++ b/test/req.is.js @@ -166,4 +166,48 @@ describe('req.is()', function () { .expect(200, '"application/json"', done) }) }) + + describe('when given an array', function () { + it('should return the first matching type', function (done) { + var app = express() + + app.use(function (req, res) { + res.json(req.is(['html', 'json'])) + }) + + request(app) + .post('/') + .type('application/json') + .send('{}') + .expect(200, '"json"', done) + }) + + it('should return false when none match', function (done) { + var app = express() + + app.use(function (req, res) { + res.json(req.is(['html', 'text'])) + }) + + request(app) + .post('/') + .type('application/json') + .send('{}') + .expect(200, 'false', done) + }) + + it('should match *type when given in array', function (done) { + var app = express() + + app.use(function (req, res) { + res.json(req.is(['text/html', '*/json'])) + }) + + request(app) + .post('/') + .type('application/json') + .send('{}') + .expect(200, '"application/json"', done) + }) + }) })