Skip to content

Commit

Permalink
Added chainable res.status(code)
Browse files Browse the repository at this point in the history
ex:

  res.status(500).send("lame")
  • Loading branch information
tj committed Jun 28, 2011
1 parent 9e4020e commit b04be51
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/response.js
Expand Up @@ -140,6 +140,11 @@ res.json = function(obj, headers, status){
return this.send(JSON.stringify(obj), headers, status);
};

res.status = function(code){
this.statusCode = code;
return this;
};

/**
* Transfer the file at the given `path`. Automatically sets
* the _Content-Type_ response header field. `next()` is called
Expand Down
12 changes: 12 additions & 0 deletions test/response.test.js
Expand Up @@ -48,6 +48,18 @@ module.exports = {
{ body: '{"name":"tj"}', headers: { 'Content-Type': json }});
},

'test #status()': function(){
var app = express.createServer();

app.get('/error', function(req, res, next){
res.status(500).send('OH NO');
});

assert.response(app,
{ url: '/error' },
{ body: 'OH NO', status: 500 });
},

'test #send()': function(){
var app = express.createServer();

Expand Down

0 comments on commit b04be51

Please sign in to comment.