diff --git a/lib/context.js b/lib/context.js index 5bb5107..88ec1ae 100644 --- a/lib/context.js +++ b/lib/context.js @@ -126,6 +126,7 @@ const proto = module.exports = { const { res } = this; // first unset all headers + /* istanbul ignore else */ if (typeof res.getHeaderNames === 'function') { res.getHeaderNames().forEach(name => res.removeHeader(name)); } else { @@ -159,6 +160,8 @@ const proto = module.exports = { * @return {Object} * @api public */ + +/* istanbul ignore else */ if (util.inspect.custom) { module.exports[util.inspect.custom] = module.exports.inspect; } diff --git a/test/context/onerror.js b/test/context/onerror.js index ddee81c..f1a44a0 100644 --- a/test/context/onerror.js +++ b/test/context/onerror.js @@ -129,7 +129,26 @@ describe('ctx.onerror(err)', () => { .expect('Internal Server Error'); }); }); + describe('when ENOENT error', () => { + it('should respond 404', () => { + const app = new Koa(); + app.use((ctx, next) => { + ctx.body = 'something else'; + const err = new Error('test for ENOENT'); + err.code = 'ENOENT'; + throw err; + }); + + const server = app.listen(); + + return request(server) + .get('/') + .expect(404) + .expect('Content-Type', 'text/plain; charset=utf-8') + .expect('Not Found'); + }); + }); describe('not http status code', () => { it('should respond 500', () => { const app = new Koa();