Reputation: 11972
I'm testing an HTTP server. I was hoping I could pass done
to describe()
, instead of just to it()
, something like this:
var request = require('supertest');
describe('Item', function(done){
request(app).get('/').end(function(req, res){
it('should have one thing', function(){
// Assert on res.body
});
it('should have another thing', function(){
// Assert on res.body
});
it('should have more things', function(){
// Assert on res.body
});
done();
});
});
This won't work, mocha never runs the tests.
The following code does work, but each time making a new HTTP request, I would prefer to use the same one.
describe('Item', function(){
it('should have one thing', function(done){
request(app).get('/').end(function(req, res){
// Assert on res.body
done();
}
});
it('should have another thing', function(done){
request(app).get('/').end(function(req, res){
// Assert on res.body
done();
}
});
it('should more things', function(done){
request(app).get('/').end(function(req, res){
// Assert on res.body
done();
}
});
});
How can I run the tests against the same response?
Upvotes: 1
Views: 300
Reputation: 150624
If you test the exact same request - then why are the assert
s distributed across multiple tests? IMHO there are two options:
The way you're doing it currently you may have inter-dependencies between your tests, and this is - IMHO - very bad test style.
Just my 2 cents.
Upvotes: 2