Skip to content

Commit

Permalink
Update new onerror test
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed Mar 2, 2017
1 parent 766f1b2 commit 9f81563
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions test/context/onerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';

const request = require('../helpers/request');
const eventToPromise = require('event-to-promise');
const Koa = require('../..');

describe('ctx.onerror(err)', () => {
Expand Down Expand Up @@ -65,14 +66,10 @@ describe('ctx.onerror(err)', () => {
expect(res.headers.has('x-csrf-token')).toBe(false);
});

it('should ignore error after headerSent', done => {
it('should ignore error after headerSent', async () => {
const app = new Koa();

app.on('error', err => {
err.message.should.equal('mock error');
err.headerSent.should.equal(true);
done();
});
const errorPromise = eventToPromise(app, 'error');

app.use(async ctx => {
ctx.status = 200;
Expand All @@ -82,10 +79,13 @@ describe('ctx.onerror(err)', () => {
ctx.body = 'response';
});

request(app.listen())
.get('/')
.expect('X-Foo', 'Bar')
.expect(200, () => {});
const res = await request(app, '/');
expect(res.status).toBe(200);
expect(res.headers.get('x-foo')).toBe('Bar');

const err = await errorPromise;
expect(err.message).toBe('mock error');
expect(err.headerSent).toBe(true);
});

describe('when invalid err.status', () => {
Expand Down

0 comments on commit 9f81563

Please sign in to comment.