Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions test/supertest.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,17 @@ describe('request.agent(app)', function() {
});
});

describe('request.agent(app, {prefix})', function() {
it('should apply prefix', function(done) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you provide a successful test (e.g. with 200 status code) as well?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I can't believe I didn't do that already!

var app = express();
var agent = request.agent(app, { prefix: '/api' });

agent
.get('/dummy')
.expect(404, 'Cannot GET /api/dummy\n', done);
});
});

describe('.<http verb> works as expected', function() {
it('.delete should work', function (done) {
var app = express();
Expand Down