-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Need equivalent to assert.response() #86
Comments
The problem is that there's not one perfect way of testing requests/responses. For example, in Socket.IO there's many specific requirements as far as testing long polling, for which assert.response just didn't work well. I think this would be a good standalone project: |
yeah ideally what we should do is use superagent, or a project on top of superagent that allows which looks something like: request(app).get('/foo').expect('bar', done) a benefit of mocha's auto-exit feature as well is that we can safely nest these without worrying about manually closing severs unlike assert.response / expresso |
Yeah a module on top of superagent would be ideal I think. Unless it's really minimal in which case it can go straight into superagent |
should be small enough to add straight in, the only default that i can think off right now that would need defaulting to something different for testing would be the redirects since you'll probably want to assert locations etc i think the rest should be fine for testing |
if app
.get('/')
.set('Content-Type', 'application/json')
.data({ foo: 'bar' })
.end(callback) I guess it could be hacked with the leading |
We can always have superagent take a express Route. |
Quick usage example for self implemented http support version: // /test/support/http.js
var app = require('../../app');
var http = require('http');
module.exports.request = function(path, cb) {
var port = app.address().port;
http.request({ path: path, port: port }).on('response', function(res) {
res.body = '';
res.on('data', function(chunk) {
res.body += chunk;
});
res.on('end', function() {
cb(res);
});
}).end();
}
// In your tests
var http = require('support/http');
require('should');
describe(...) {
it(...) {
http.request('/', function(res) {
res.statusCode.should.equal(200);
});
}
} |
closing for now since it's semi-unrelated (mocha wont bundle anything like this) |
Has there been any change with this - ie. any new works created making this possible? Can't get neither @MarioBehrendt 's solution or the |
My version is pretty much a simple version of TJ's file. What's the problem? Can you paste your code and the errors, please? |
Sorry. Had a syntax error that I overlooked. Is there a way that I can test Are you guys sure that this can't be included or at least mentioned in in the documentation? I absolutely pulled my hair before I found this post. Performing response-testing probably is what many people are looking for and it's a shame that they choose a different testing component when mocha seems so mature. |
@theindustry there's no reason to package it in mocha, it's unrelated to the client-side and it's not the be-all end-all solution for testing HTTP. Eventually I'll be recommending visionmedia/superagent for testing HTTP related stuff but it's not quite there yet |
Expresso had a really easy way to test servers and their responses: assert.response(server, ...)
I saw you use a small request class (support/http) in connect and express, but copying it to my code didn't work as expected. An official tool to ease this task would be really awesome.
The text was updated successfully, but these errors were encountered: