Permalink
Browse files

Added acceptance test for cookies.

  • Loading branch information...
1 parent ad3f1e8 commit ac387caf2157f1d70f2ebd5fddb15d3db83c2b96 @slaskis slaskis committed with tj Dec 12, 2011
Showing with 40 additions and 4 deletions.
  1. +7 −4 examples/cookies/app.js
  2. +33 −0 test/acceptance/cookies.js
View
@@ -4,7 +4,7 @@
*/
var express = require('../../')
- , app = express();
+ , app = module.exports = express();
// add favicon() before logger() so
@@ -15,7 +15,8 @@ var express = require('../../')
app.use(express.favicon());
// custom log format
-app.use(express.logger(':method :url'));
+if ('test' != process.env.NODE_ENV)
+ app.use(express.logger(':method :url'));
// parses request cookies, populating
// req.cookies and req.signedCookies
@@ -47,5 +48,7 @@ app.post('/', function(req, res){
res.redirect('back');
});
-app.listen(3000);
-console.log('Express started on port 3000');
+if (!module.parent){
+ app.listen(3000);
+ console.log('Express started on port 3000');
+}
View
@@ -0,0 +1,33 @@
+var app = require('../../examples/cookies/app')
+ , request = require('../support/http');
+
+describe('cookies', function(){
+ describe('GET /', function(){
+ it('should have a form', function(done){
+ request(app)
+ .get('/')
+ .expect(/<form/,done)
+ })
+ it('should respond with no cookies', function(done){
+ request(app)
+ .get('/')
+ .end(function(res){
+ res.headers.should.not.have.property('set-cookie')
+ done()
+ })
+ })
+ })
+
+ describe('POST /', function(){
+ it('should set a cookie', function(done){
+ request(app)
+ .post('/')
+ .set('Content-Type','application/x-www-form-urlencoded')
+ .write('remember=1')
+ .end(function(res){
+ res.headers.should.have.property('set-cookie')
+ done()
+ })
+ })
+ })
+})

0 comments on commit ac387ca

Please sign in to comment.