add GeneratorFunction assertion for app.use(). Closes #120
breaks old old shit but thats ok, super early in the game
This commit is contained in:
parent
fefb3c59ae
commit
70971dcb53
3 changed files with 23 additions and 12 deletions
|
@ -10,6 +10,7 @@ var request = require('./request');
|
|||
var response = require('./response');
|
||||
var Cookies = require('cookies');
|
||||
var Keygrip = require('keygrip');
|
||||
var assert = require('assert');
|
||||
var Stream = require('stream');
|
||||
var http = require('http');
|
||||
var co = require('co');
|
||||
|
@ -71,12 +72,13 @@ app.listen = function(){
|
|||
/**
|
||||
* Use the given middleware `fn`.
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @param {GeneratorFunction} fn
|
||||
* @return {Application} self
|
||||
* @api public
|
||||
*/
|
||||
|
||||
app.use = function(fn){
|
||||
assert('GeneratorFunction' == fn.constructor.name, 'app.use() requires a generator function');
|
||||
debug('use %s', fn.name || '-');
|
||||
this.middleware.push(fn);
|
||||
return this;
|
||||
|
|
|
@ -58,6 +58,17 @@ describe('app.use(fn)', function(){
|
|||
done();
|
||||
});
|
||||
})
|
||||
|
||||
it('should error when a non-generator function is passed', function(done){
|
||||
var app = koa();
|
||||
|
||||
try {
|
||||
app.use(function(){});
|
||||
} catch (err) {
|
||||
err.message.should.equal('app.use() requires a generator function');
|
||||
done();
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('app.respond', function(){
|
||||
|
|
|
@ -40,8 +40,7 @@ describe('res.status=', function(){
|
|||
it('should strip content related header fields', function(done){
|
||||
var app = koa();
|
||||
|
||||
app.use(function(next){
|
||||
return function *(){
|
||||
app.use(function *(){
|
||||
this.body = { foo: 'bar' };
|
||||
this.set('Content-Type', 'application/json');
|
||||
this.set('Content-Length', '15');
|
||||
|
@ -50,7 +49,6 @@ describe('res.status=', function(){
|
|||
assert(null == this.response.header['content-type']);
|
||||
assert(null == this.response.header['content-length']);
|
||||
assert(null == this.response.header['transfer-encoding']);
|
||||
}
|
||||
});
|
||||
|
||||
request(app.listen())
|
||||
|
|
Loading…
Reference in a new issue