diff --git a/lib/context.js b/lib/context.js index dbd796e..5085548 100644 --- a/lib/context.js +++ b/lib/context.js @@ -187,7 +187,7 @@ module.exports = { } // json - if (setType) this.type = 'json'; + this.type = 'json'; }, /** diff --git a/test/context.js b/test/context.js index ba916da..ab0604b 100644 --- a/test/context.js +++ b/test/context.js @@ -30,11 +30,23 @@ describe('ctx.body=', function(){ assert('image/png' == ctx.responseHeader['content-type']); }) + describe('when body is an object', function(){ + it('should override as json', function(){ + var ctx = context(); + + ctx.body = 'hey'; + assert('text/html; charset=utf-8' == ctx.responseHeader['content-type']); + + ctx.body = { foo: 'bar' }; + assert('application/json' == ctx.responseHeader['content-type']); + }) + }) + it('should override length', function(){ var ctx = context(); ctx.type = 'html'; ctx.body = 'something'; - assert.equal(ctx.responseLength, 9); + ctx.responseLength.should.equal(9); }) })