Skip to content

Commit 9904aa5

Browse files
committedNov 11, 2017
Add query params support tests
1 parent bd9cbff commit 9904aa5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
 

‎test/lib/router.js

+25
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,31 @@ describe('Router', function () {
11341134
done();
11351135
});
11361136

1137+
it('generates URL for given route name with params and query params', function(done) {
1138+
var app = new Koa();
1139+
var router = new Router();
1140+
router.get('categories', '/categories/:name', function (ctx) {
1141+
ctx.status = 204;
1142+
});
1143+
var url = router.url('categories', { name: 'programming' }, {
1144+
query: { page: 3, limit: 10 }
1145+
});
1146+
url.should.equal('/categories/programming?page=3&limit=10');
1147+
done();
1148+
})
1149+
1150+
it('generates URL for given route name without params and query params', function(done) {
1151+
var app = new Koa();
1152+
var router = new Router();
1153+
router.get('category', '/category', function (ctx) {
1154+
ctx.status = 204;
1155+
});
1156+
var url = router.url('category', {
1157+
query: { page: 3, limit: 10 }
1158+
});
1159+
url.should.equal('/category?page=3&limit=10');
1160+
done();
1161+
})
11371162
});
11381163

11391164
describe('Router#param()', function () {

0 commit comments

Comments
 (0)
Please sign in to comment.