Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

complete meta test test

Tj Holowaychukea3364ed254e
diff --git a/test/unit/http.meta.2.js b/test/unit/http.meta.2.js
index 3ea01bad..9b7585c8 100644
--- a/test/unit/http.meta.2.js
+++ b/test/unit/http.meta.2.js
@@ -22,22 +22,40 @@ var server = http.createServer(function(req, res){
server.listen(8899);
function get(url, header) {
+ var fields
+ , expected;
+
+ if (header) {
+ fields = Object.keys(header).map(function(field){
+ return field + ': ' + header[field];
+ }).join(', ');
+ }
+
+ function request(done) {
+ http.get({ path: url, port: 8899, headers: header }, function(res){
+ var buf = '';
+ res.statusCode.should.equal(200);
+ res.setEncoding('utf8');
+ res.on('data', function(chunk){ buf += chunk });
+ res.on('end', function(){
+ buf.should.equal(expected);
+ done();
+ });
+ })
+ }
+
return {
should: {
respond: function(body){
+ expected = body;
describe('GET ' + url, function(){
- it('should respond with "' + body + '"', function(done){
- http.get({ path: url, port: 8899, headers: header }, function(res){
- var buf = '';
- res.statusCode.should.equal(200);
- res.setEncoding('utf8');
- res.on('data', function(chunk){ buf += chunk });
- res.on('end', function(){
- buf.should.equal(body);
- done();
- });
- })
- });
+ if (fields) {
+ describe('when given ' + fields, function(){
+ it('should respond with "' + body + '"', request);
+ });
+ } else {
+ it('should respond with "' + body + '"', request);
+ }
});
}
}