Skip to content

armgit / mocha

Public Imported from GitHub
0

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

moar meta example

Tj Holowaychuke5e63e77d3ad
diff --git a/test/unit/http.meta.js b/test/unit/http.meta.js
index 7af8657f..f083c46a 100644
--- a/test/unit/http.meta.js
+++ b/test/unit/http.meta.js
@@ -2,21 +2,28 @@
var http = require('http');
var server = http.createServer(function(req, res){
+ var accept = req.headers.accept || ''
+ , json = ~accept.indexOf('json');
+
switch (req.url) {
case '/':
res.end('hello');
break;
case '/users':
- res.end('tobi, loki, jane');
+ if (json) {
+ res.end('["tobi","loki","jane"]');
+ } else {
+ res.end('tobi, loki, jane');
+ }
break;
}
})
server.listen(8889);
-function get(url, body) {
+function get(url, body, header) {
return function(done){
- http.get({ path: url, port: 8889 }, function(res){
+ http.get({ path: url, port: 8889, headers: header }, function(res){
var buf = '';
res.statusCode.should.equal(200);
res.setEncoding('utf8');
@@ -31,10 +38,15 @@ function get(url, body) {
describe('http', function(){
describe('GET /', function(){
- it('should respond with hello', get('/', 'hello'))
+ it('should respond with hello',
+ get('/', 'hello'))
})
describe('GET /users', function(){
- it('should respond with users', get('/users', 'tobi, loki, jane'))
+ it('should respond with users',
+ get('/users', 'tobi, loki, jane'))
+
+ it('should respond with users',
+ get('/users', '["tobi","loki","jane"]', { Accept: 'application/json' }))
})
})
\ No newline at end of file