test: add a test case for *respond !socket.writable
https://github.com/koajs/koa/commit/9fe483ca767b64de3e9b9e2c78b7bfaf4208 61c2#diff-5372f626ee15242f1e2c6eb31655b4faR187
This commit is contained in:
parent
d3e3c4d117
commit
23548b6c97
1 changed files with 22 additions and 0 deletions
|
@ -23,6 +23,28 @@ describe('app', function(){
|
|||
.get('/')
|
||||
.end(function(){});
|
||||
})
|
||||
|
||||
it('should not .writeHead when !socket.writable', function(done){
|
||||
var app = koa();
|
||||
|
||||
app.use(function *(next){
|
||||
// set .writable to false
|
||||
this.socket.writable = false;
|
||||
this.status = 204;
|
||||
// throw if .writeHead or .end is called
|
||||
this.res.writeHead =
|
||||
this.res.end = function () {
|
||||
throw new Error('response sent');
|
||||
};
|
||||
})
|
||||
|
||||
// hackish, but the response should occur in a single ticket
|
||||
setImmediate(done);
|
||||
|
||||
request(app.listen())
|
||||
.get('/')
|
||||
.end(function(){});
|
||||
})
|
||||
})
|
||||
|
||||
describe('app.use(fn)', function(){
|
||||
|
|
Loading…
Reference in a new issue