-
Notifications
You must be signed in to change notification settings - Fork 25
request.agent undefined #1
Comments
We don't use the agent in our codebase, so I didn't bother to wrap it with promise support. Marking as a bug since you'd expect all SuperTest features to work. Thanks! Shouldn't be too hard; I'll add it to the todo list. Feel free to open a PR in the meantime! |
I tried the following, naively copying the wrapping logic and applying it to request.agent's result but it didn't do the trick: function wrap (request) {
// Wrap all SuperTest functions (`get`, `post`, etc.) so we can inject a
// `then` method into the returned `Test` instance
return _.mapValues(request, function wrap(fn) {
return function () {
var test = fn.apply(null, arguments);
test.then = then;
return test;
};
});
}
function _request () {
// Let SuperTest work its magic on whatever arguments we receive
return wrap(supertest.apply(null, arguments));
}
_request.agent = function () {
// Let SuperTest work its magic on whatever arguments we receive
return wrap(supertest.agent.apply(supertest, arguments));
}
module.exports = _request; No time to dig yet |
I solved it in my app by dropping this hack in my tests: var Test = require('supertest/lib/test');
Test.prototype.then = function (onResolve, onReject, onProgress) {
return Promise.promisify(this.end, this)().then(onResolve, onReject, onProgress);
} Seems to apply better. |
Thanks for the inspiration, @naholyr! The issue was that Your hack is elegant, but it duck-punches promise support into SuperTest application-wide. This is probably fine since adding a Let me know if you run into trouble. |
Great job \o/ On 19 May 2014 19:35, Nikhil Benesch notifications@github.com wrote:
Nicolas Chambrier, aka naholyr Blog : http://naholyr.fr |
There is currently no way to create a persistent client (cookies & co) using
supertest-as-promised
.agent() whereas it's available insupertest
The text was updated successfully, but these errors were encountered: