Fix issue when app.use() is called with empty value
This commit is contained in:
parent
69ad7ad4a5
commit
d134fff9e8
2 changed files with 4 additions and 6 deletions
|
@ -99,9 +99,9 @@ module.exports = class Application extends Emitter {
|
|||
*/
|
||||
|
||||
use(fn) {
|
||||
debug('use %s', fn._name || fn.name || '-');
|
||||
if (typeof fn !== 'function') throw new TypeError('middleware must be a function!');
|
||||
if (isGeneratorFunction(fn)) throw new TypeError('Support for generators has been removed. See the documentation for examples of how to convert old middleware https://github.com/koajs/koa#example-with-old-signature');
|
||||
debug('use %s', fn._name || fn.name || '-');
|
||||
this.middleware.push(fn);
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -54,11 +54,10 @@ describe('app.use(fn)', () => {
|
|||
.end(done);
|
||||
});
|
||||
|
||||
it('should throw error for non function', done => {
|
||||
it('should throw error for non function', () => {
|
||||
const app = new Koa();
|
||||
|
||||
(() => app.use('not a function')).should.throw('middleware must be a function!');
|
||||
done();
|
||||
[null, undefined, 0, false, 'not a function'].forEach(v => (() => app.use(v)).should.throw('middleware must be a function!'));
|
||||
});
|
||||
|
||||
it('should throw error for generator', () => {
|
||||
|
@ -67,10 +66,9 @@ describe('app.use(fn)', () => {
|
|||
(() => app.use(function *(){})).should.throw(/.+/);
|
||||
});
|
||||
|
||||
it('should throw error for non function', done => {
|
||||
it('should throw error for non function', () => {
|
||||
const app = new Koa();
|
||||
|
||||
(() => app.use('not a function')).should.throw('middleware must be a function!');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue