Skip to content

Commit

Permalink
more static() tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Nov 12, 2011
1 parent 3567ba5 commit 59d1d29
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions test/fixtures/foo bar
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
baz
1 change: 1 addition & 0 deletions test/fixtures/users/tobi.txt
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
ferret
24 changes: 24 additions & 0 deletions test/static.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,4 +12,28 @@ describe('connect.static()', function(){
.get('/todo.txt') .get('/todo.txt')
.expect('- groceries', done); .expect('- groceries', done);
}) })

it('should support nesting', function(done){
app.request()
.get('/users/tobi.txt')
.expect('ferret', done);
})

it('should set Content-Type', function(done){
app.request()
.get('/todo.txt')
.expect('Content-Type', 'text/plain; charset=UTF-8', done);
})

it('should default max-age=0', function(done){
app.request()
.get('/todo.txt')
.expect('Cache-Control', 'public, max-age=0', done);
})

it('should support urlencoded pathnames', function(done){
app.request()
.get('/foo%20bar')
.expect('baz', done);
})
}) })
18 changes: 13 additions & 5 deletions test/support/http.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -61,13 +61,21 @@ Request.prototype.request = function(method, path){
}; };


Request.prototype.expect = function(body, fn){ Request.prototype.expect = function(body, fn){
var args = arguments;
this.end(function(res){ this.end(function(res){
if ('number' == typeof body) { switch (args.length) {
res.statusCode.should.equal(body); case 3:
} else { res.headers.should.have.property(body.toLowerCase(), args[1]);
res.body.should.equal(body); args[2]();
break;
default:
if ('number' == typeof body) {
res.statusCode.should.equal(body);
} else {
res.body.should.equal(body);
}
fn();
} }
fn();
}); });
}; };


Expand Down

0 comments on commit 59d1d29

Please sign in to comment.