Skip to content

armgit / mocha

Public Imported from GitHub
0

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

moar meta 2 example

Tj Holowaychukcf5fb1e84e30
diff --git a/test/unit/http.meta.2.js b/test/unit/http.meta.2.js
index 4dc30148..3ea01bad 100644
--- a/test/unit/http.meta.2.js
+++ b/test/unit/http.meta.2.js
@@ -21,32 +21,33 @@ var server = http.createServer(function(req, res){
server.listen(8899);
-function get(url, body, header) {
- return 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();
- });
- })
- }
-}
-
-describe('http requests', function(){
- describe('GET /', function(){
- it('should respond with hello',
- get('/', 'hello'))
- })
+function get(url, header) {
+ return {
+ should: {
+ respond: function(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();
+ });
+ })
+ });
+ });
+ }
+ }
+ };
- describe('GET /users', function(){
- it('should respond with users',
- get('/users', 'tobi, loki, jane'))
+}
- it('should respond with users',
- get('/users', '["tobi","loki","jane"]', { Accept: 'application/json' }))
- })
+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"]')
})
\ No newline at end of file