From 713ddf13e14c2dacb5a8183c47aea505e633fce3 Mon Sep 17 00:00:00 2001 From: Ozzy Walsh <18150509+ozzywalsh@users.noreply.github.com> Date: Sat, 19 Jan 2019 15:59:54 +0000 Subject: [PATCH 1/2] Call this._setDefaults in TestAgent http methods --- lib/agent.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/agent.js b/lib/agent.js index 54ce47f1..16c9560a 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -58,6 +58,7 @@ methods.forEach(function(method) { req.on('redirect', this._saveCookies.bind(this)); req.on('redirect', this._attachCookies.bind(this, req)); this._attachCookies(req); + this._setDefaults(req); return req; }; From 3b13e91acc03160fd751b41ed76a488abcadc6be Mon Sep 17 00:00:00 2001 From: Ozzy Walsh <18150509+ozzywalsh@users.noreply.github.com> Date: Sat, 19 Jan 2019 17:27:01 +0000 Subject: [PATCH 2/2] Test global agent settings work --- test/supertest.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/supertest.js b/test/supertest.js index 379f34a8..48ab232e 100644 --- a/test/supertest.js +++ b/test/supertest.js @@ -833,7 +833,8 @@ describe('request(app)', function () { describe('request.agent(app)', function () { const app = express(); - const agent = request.agent(app); + const agent = request.agent(app) + .set('header', 'hey'); app.use(cookieParser()); @@ -842,11 +843,16 @@ describe('request.agent(app)', function () { res.send(); }); - app.get('/return', function (req, res) { + app.get('/return_cookies', function (req, res) { if (req.cookies.cookie) res.send(req.cookies.cookie); else res.send(':('); }); + app.get('/return_headers', function (req, res) { + if (req.get('header')) res.send(req.get('header')); + else res.send(':('); + }); + it('should save cookies', function (done) { agent .get('/') @@ -855,7 +861,13 @@ describe('request.agent(app)', function () { it('should send cookies', function (done) { agent - .get('/return') + .get('/return_cookies') + .expect('hey', done); + }); + + it('should send global agent headers', function (done) { + agent + .get('/return_headers') .expect('hey', done); }); });