koa-router
Advanced tools
Comparing version 3.2.1 to 3.2.2
@@ -45,2 +45,13 @@ /** | ||
// ensure middleware is a function | ||
middleware.forEach(function(fn) { | ||
var type = (typeof fn); | ||
if (type != 'function') { | ||
throw new Error( | ||
methods.toString() + " `" + (name || path) +"`: `middleware` " | ||
+ "must be a function, not `" + type + "`" | ||
); | ||
} | ||
}); | ||
if (middleware.length > 1) { | ||
@@ -47,0 +58,0 @@ this.middleware = compose(middleware); |
@@ -122,4 +122,3 @@ /** | ||
var args = Array.prototype.slice.call(arguments); | ||
args.splice(typeof path == 'function' ? 1 : 2, 0, [method]); | ||
args.splice(typeof path == 'string' ? 2 : 1, 0, [method]); | ||
this.register.apply(this, args); | ||
@@ -126,0 +125,0 @@ return this; |
@@ -9,3 +9,3 @@ { | ||
"author": "Alex Mingoia <talk@alexmingoia.com>", | ||
"version": "3.2.1", | ||
"version": "3.2.2", | ||
"keywords": [ | ||
@@ -12,0 +12,0 @@ "koa", |
@@ -154,3 +154,20 @@ /** | ||
}); | ||
}) | ||
}); | ||
it('should throw friendly error message when handle not exists', function() { | ||
var app = koa(); | ||
app.use(router(app)); | ||
var notexistHandle = undefined; | ||
(function () { | ||
app.get('/foo', notexistHandle); | ||
}).should.throw('get `/foo`: `middleware` must be a function, not `undefined`'); | ||
(function () { | ||
app.get('foo router', '/foo', notexistHandle); | ||
}).should.throw('get `foo router`: `middleware` must be a function, not `undefined`'); | ||
(function () { | ||
app.post('/foo', function() {}, notexistHandle); | ||
}).should.throw('post `/foo`: `middleware` must be a function, not `undefined`'); | ||
}); | ||
}); | ||
@@ -160,3 +177,3 @@ | ||
it('generates route URL', function() { | ||
var route = new Route('/:category/:title', ['get'], function* () {}, 'books'); | ||
var route = new Route('/:category/:title', ['get'], [function* () {}], 'books'); | ||
var url = route.url({ category: 'programming', title: 'how-to-node' }); | ||
@@ -169,3 +186,3 @@ url.should.equal('/programming/how-to-node'); | ||
it('escapes using encodeURIComponent()', function() { | ||
var route = new Route('/:category/:title', ['get'], function *() {}, 'books'); | ||
var route = new Route('/:category/:title', ['get'], [function *() {}], 'books'); | ||
var url = route.url({ category: 'programming', title: 'how to node' }); | ||
@@ -172,0 +189,0 @@ url.should.equal('/programming/how%20to%20node'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32522
866