2014-01-24 22:29:57 +00:00
|
|
|
|
|
|
|
var koa = require('../..');
|
|
|
|
var request = require('supertest');
|
|
|
|
|
|
|
|
describe('ctx.onerror(err)', function(){
|
|
|
|
it('should respond', function(done){
|
|
|
|
var app = koa();
|
|
|
|
|
|
|
|
app.use(function *(next){
|
|
|
|
this.body = 'something else';
|
|
|
|
|
2014-03-13 01:29:14 +00:00
|
|
|
this.throw(418, 'boom');
|
2014-01-24 22:29:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
var server = app.listen();
|
|
|
|
|
|
|
|
request(server)
|
|
|
|
.get('/')
|
2014-03-13 01:29:14 +00:00
|
|
|
.expect(418)
|
2014-01-24 22:29:57 +00:00
|
|
|
.expect('Content-Type', 'text/plain; charset=utf-8')
|
|
|
|
.expect('Content-Length', '4')
|
|
|
|
.end(done);
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should unset all headers', function(done){
|
|
|
|
var app = koa();
|
|
|
|
|
|
|
|
app.use(function *(next){
|
|
|
|
this.set('Vary', 'Accept-Encoding');
|
|
|
|
this.set('X-CSRF-Token', 'asdf');
|
|
|
|
this.body = 'response';
|
|
|
|
|
2014-03-13 01:29:14 +00:00
|
|
|
this.throw(418, 'boom');
|
2014-01-24 22:29:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
var server = app.listen();
|
|
|
|
|
|
|
|
request(server)
|
|
|
|
.get('/')
|
2014-03-13 01:29:14 +00:00
|
|
|
.expect(418)
|
2014-01-24 22:29:57 +00:00
|
|
|
.expect('Content-Type', 'text/plain; charset=utf-8')
|
|
|
|
.expect('Content-Length', '4')
|
|
|
|
.end(function(err, res){
|
|
|
|
if (err) return done(err);
|
|
|
|
|
|
|
|
res.headers.should.not.have.property('vary');
|
|
|
|
res.headers.should.not.have.property('x-csrf-token');
|
|
|
|
res.headers.should.not.have.property('x-powered-by');
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|