From 1edd6ec69a1a6900f1b07b8af886afe6e5ca7546 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 29 Mar 2015 11:25:28 +0800 Subject: [PATCH] test: improve test coverage for application and response --- lib/application.js | 1 + test/application.js | 24 ++++++++++++++++++++++++ test/response/append.js | 3 ++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/application.js b/lib/application.js index e353a81..ef19e7b 100644 --- a/lib/application.js +++ b/lib/application.js @@ -204,6 +204,7 @@ function *respond(next) { if (null == body) { this.type = 'text'; body = this.message || String(code); + /* istanbul ignore else */ if (body) this.length = Buffer.byteLength(body); return res.end(body); } diff --git a/test/application.js b/test/application.js index 0158874..06958bf 100644 --- a/test/application.js +++ b/test/application.js @@ -48,6 +48,14 @@ describe('app', function(){ .get('/') .end(function(){}); }) + + it('should set development env when NODE_ENV missing', function(){ + var NODE_ENV = process.env.NODE_ENV; + process.env.NODE_ENV = ''; + var app = koa(); + process.env.NODE_ENV = NODE_ENV; + assert.equal(app.env, 'development'); + }) }) describe('app.toJSON()', function(){ @@ -180,6 +188,22 @@ describe('app.onerror(err)', function(){ done(); }) + + it('should use err.toString() instad of err.stack', function(done){ + var app = koa(); + app.env = 'dev'; + + var err = new Error('mock stack null'); + err.stack = null; + + var output = stderr.inspectSync(function() { + app.onerror(err); + }); + + output.should.eql(["\n", " Error: mock stack null\n", "\n"]); + + done(); + }) }) describe('app.respond', function(){ diff --git a/test/response/append.js b/test/response/append.js index 4f3cd89..83fd2c3 100644 --- a/test/response/append.js +++ b/test/response/append.js @@ -13,7 +13,8 @@ describe('ctx.append(name, val)', function(){ var ctx = context(); ctx.append('Set-Cookie', ['foo=bar', 'fizz=buzz']); - ctx.response.header['set-cookie'].should.eql(['foo=bar', 'fizz=buzz']); + ctx.append('Set-Cookie', 'hi=again'); + ctx.response.header['set-cookie'].should.eql(['foo=bar', 'fizz=buzz', 'hi=again']); }) it('should get reset by res.set(field, val)', function (){