Skip to content

armgit / mocha

Public Imported from GitHub
0

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

tweak meta http example

Tj Holowaychuk682cace98508
diff --git a/test/unit/http.meta.2.js b/test/unit/http.meta.2.js
index 9b7585c8..fbd7a9d8 100644
--- a/test/unit/http.meta.2.js
+++ b/test/unit/http.meta.2.js
@@ -21,15 +21,10 @@ var server = http.createServer(function(req, res){
server.listen(8899);
-function get(url, header) {
+function get(url) {
var fields
- , expected;
-
- if (header) {
- fields = Object.keys(header).map(function(field){
- return field + ': ' + header[field];
- }).join(', ');
- }
+ , expected
+ , header = {};
function request(done) {
http.get({ path: url, port: 8899, headers: header }, function(res){
@@ -45,8 +40,17 @@ function get(url, header) {
}
return {
+ set: function(field, val){
+ header[field] = val;
+ return this;
+ },
+
should: {
respond: function(body){
+ fields = Object.keys(header).map(function(field){
+ return field + ': ' + header[field];
+ }).join(', ');
+
expected = body;
describe('GET ' + url, function(){
if (fields) {
@@ -64,8 +68,16 @@ function get(url, header) {
}
describe('http server', function(){
- var json = 'application/json';
- get('/').should.respond('hello')
- get('/users').should.respond('tobi, loki, jane')
- get('/users', { Accept: json }).should.respond('["tobi","loki","jane"]')
+ get('/')
+ .should
+ .respond('hello')
+
+ get('/users')
+ .should
+ .respond('tobi, loki, jane')
+
+ get('/users')
+ .set('Accept', 'application/json')
+ .should
+ .respond('["tobi","loki","jane"]')
})
\ No newline at end of file