diff --git a/lib/agent.js b/lib/agent.js index 5f16ae3d..d7bef5c5 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -29,6 +29,7 @@ function TestAgent(app, options) { this._ca = options.ca; this._key = options.key; this._cert = options.cert; + this._prefix = options.prefix; } Agent.call(this); this.app = app; @@ -43,7 +44,8 @@ TestAgent.prototype.__proto__ = Agent.prototype; // override HTTP verb methods methods.forEach(function(method) { TestAgent.prototype[method] = function(url, fn) { // eslint-disable-line no-unused-vars - var req = new Test(this.app, method.toUpperCase(), url); + // TODO: support prefix on actual urls + var req = new Test(this.app, method.toUpperCase(), (this._prefix || '') + url); req.ca(this._ca); req.cert(this._cert); req.key(this._key); diff --git a/test/supertest.js b/test/supertest.js index c9a4927b..03590e86 100644 --- a/test/supertest.js +++ b/test/supertest.js @@ -815,6 +815,17 @@ describe('request.agent(app)', function() { }); }); +describe('request.agent(app, {prefix})', function() { + it('should apply prefix', function(done) { + var app = express(); + var agent = request.agent(app, { prefix: '/api' }); + + agent + .get('/dummy') + .expect(404, 'Cannot GET /api/dummy\n', done); + }); +}); + describe('. works as expected', function() { it('.delete should work', function (done) { var app = express();