Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added first batch of acceptance tests for examples

  • Loading branch information...
commit 29ef828b9cda45680f2f6342b43aa90ff6060f32 1 parent 39ae443
@tj tj authored
View
5 Makefile
@@ -12,6 +12,9 @@ test:
--growl \
$(TESTS)
+test-acceptance:
+ @$(MAKE) test TESTS=test/acceptance/*.js
+
docs: $(HTMLDOCS)
@ echo "... generating TOC"
@./support/toc.js docs/guide.html
@@ -35,4 +38,4 @@ benchmark:
docclean:
rm -f docs/*.{1,html}
-.PHONY: site test benchmark docs docclean
+.PHONY: site test benchmark docs docclean test-acceptance
View
13 examples/content-negotiation/app.js
@@ -3,8 +3,10 @@
* Module dependencies.
*/
-var express = require('../../')
- , app = express();
+var express = require('../../');
+
+// expose the app for require()ing
+var app = module.exports = express();
var users = [
{ name: 'tobi' }
@@ -45,5 +47,8 @@ app.get('/users', function(req, res, next){
}).join(', '));
});
-app.listen(3000);
-console.log('Express server listening on port 3000');
+// not being require()d
+if (!module.parent) {
+ app.listen(3000);
+ console.log('Express server listening on port 3000');
+}
View
54 test/acceptance/content-negotiation.js
@@ -0,0 +1,54 @@
+
+var request = require('../support/http')
+ , app = require('../../examples/content-negotiation/app');
+
+describe('content-negotiation', function(){
+ describe('GET /users', function(){
+ it('should support json', function(done){
+ request(app)
+ .get('/users')
+ .set('Accept', 'application/json')
+ .end(function(res){
+ res.should.have.header('Content-Type', 'application/json; charset=utf-8');
+ res.should.have.status(200);
+ res.body.should.equal('[{"name":"tobi"},{"name":"loki"},{"name":"jane"}]');
+ done();
+ });
+ })
+
+ it('should support html', function(done){
+ request(app)
+ .get('/users')
+ .set('Accept', 'text/html')
+ .end(function(res){
+ res.should.have.header('Content-Type', 'text/html; charset=utf-8');
+ res.should.have.status(200);
+ res.body.should.equal('<ul><li>tobi</li>\n<li>loki</li>\n<li>jane</li></ul>');
+ done();
+ });
+ })
+
+ it('should support plain text', function(done){
+ request(app)
+ .get('/users')
+ .set('Accept', 'text/plain')
+ .end(function(res){
+ res.should.have.header('Content-Type', 'text/plain');
+ res.should.have.status(200);
+ res.body.should.equal('tobi, loki, jane');
+ done();
+ });
+ })
+
+ it('should default to application/json', function(done){
+ request(app)
+ .get('/users')
+ .end(function(res){
+ res.should.have.header('Content-Type', 'application/json; charset=utf-8');
+ res.should.have.status(200);
+ res.body.should.equal('[{"name":"tobi"},{"name":"loki"},{"name":"jane"}]');
+ done();
+ });
+ })
+ })
+})

0 comments on commit 29ef828

Please sign in to comment.
Something went wrong with that request. Please try again.