-
Notifications
You must be signed in to change notification settings - Fork 761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Access to superagent's agent? #26
Comments
I was just about to request this too. I'm using Supertest to test our website and Ajax APIs, and was really looking forward to the automatic cookie/session support in the update to Supertest/Superagent. Thanks! |
A workaround is that you can require both supertest and superagent and use superagent to get the agent for the tests that need sessions and cookies. But you also have to then fully qualify your urls. This addition would be a nice convenience. |
How do you hook up the Superagent agent to the Supertest functionality? |
I didn't. Obviously you could, and that's what I'm suggesting in this issue. For now, I was just using both of them var request = require('supertest') // supertest ... |
+1 |
I'd love too see that feature implemented, even wanted to do this myself, but unfortunatelly superagent's agent implementation doesn't fit well in current supertest design :( |
Perhaps supertest could expose a similar agent API as superagent? var request = require('supertest').agent();
request(app)
.get('/login')
// ...
request(app)
.get('/admin')
// ... |
I made it working although in not prettiest way (#32). In my fork you can use supertest right now like that: |
Finally I've wrote separate module (https://github.com/codefather/supertest-chai) which is not based but very similar to supertest. Example: var chaiSupertest = require('chai-supertest');
var request = chaiSupertest.request;
var chai = require("chai");
chai.should();
chai.use(chaiSupertest.httpAsserts);
var express = require('express');
var app = express();
app.get('/user', function (req, res) {
res.send(201, { name: 'tobi' });
});
app.get('/questions', function (req, res) {
res.send(200, 'test');
});
request(app)
.get('/user')
.end(function (res) {
res.should.be.json;
res.should.have.status(201);
res.should.have.header('Content-Length', '15');
res.body.should.deep.equal({name: 'tobi'});
});
var user = request(app).agent();
user
.get('/questions')
.end(function (res) {
res.should.be.html;
res.should.have.status(200);
res.should.have.header('Content-Length', '4');
res.text.should.equal('test');
}); |
+1 - this'd be really nice to have. |
+1 |
2 similar comments
+1 |
+1 |
+1, unusable without it. |
+1 |
1 similar comment
+1 |
[Original: +1, is there a recommended way of testing sessions without this functionality?] After inspecting the code I realized this functionality is already built into supertest (just not very well documented). Just do: var supertest = require('supertest');
var app = require('../lib/your_app_location');
var request = supertest(app);
var agent = supertest.agent(app); Works like a charm, this issue should be closed, and so should be #46 |
Just need to add docs for this. |
Supertest exposes the superagent Request methods, but not the agent. Could it expose agent so you could use supertest with sessions/cookies?
The text was updated successfully, but these errors were encountered: