Skip to content

Commit

Permalink
Added acceptance test for cookies.
Browse files Browse the repository at this point in the history
  • Loading branch information
slaskis authored and tj committed Feb 18, 2012
1 parent ad3f1e8 commit ac387ca
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
11 changes: 7 additions & 4 deletions examples/cookies/app.js
Expand Up @@ -4,7 +4,7 @@
*/

var express = require('../../')
, app = express();
, app = module.exports = express();


// add favicon() before logger() so
Expand All @@ -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
Expand Down Expand Up @@ -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');
}
33 changes: 33 additions & 0 deletions test/acceptance/cookies.js
@@ -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.