test&cov: add test case (#1211)

This commit is contained in:
小菜 2018-07-01 01:29:19 +08:00 committed by Yiyu He
parent 02feadc4db
commit 2cdbc52e38
2 changed files with 22 additions and 0 deletions

View file

@ -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;
}

View file

@ -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();