Skip to content

Commit

Permalink
Fix router#url tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sinewyk committed Apr 8, 2020
1 parent 78a2929 commit 5fcc2ed
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions test/lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -1223,9 +1223,15 @@ describe('Router', function () {
router.get('books', '/:category/:title', function (ctx) {
ctx.status = 204;
});
var url = router.url('books', { category: 'programming', title: 'how to node' });
var url = router.url(
'books',
{ category: 'programming', title: 'how to node' },
{ encode: encodeURIComponent }
);
url.should.equal('/programming/how%20to%20node');
url = router.url('books', 'programming', 'how to node');
url = router.url('books', 'programming', 'how to node', {
encode: encodeURIComponent,
});
url.should.equal('/programming/how%20to%20node');
done();

Expand All @@ -1245,9 +1251,15 @@ describe('Router', function () {
});
router.use(embeddedRouter.routes());
app.use(router.routes());
var url = router.url('chapters', { chapterName: 'Learning ECMA6', pageNumber: 123 });
var url = router.url(
'chapters',
{ chapterName: 'Learning ECMA6', pageNumber: 123 },
{ encode: encodeURIComponent }
);
url.should.equal('/books/chapters/Learning%20ECMA6/123');
url = router.url('chapters', 'Learning ECMA6', 123);
url = router.url('chapters', 'Learning ECMA6', 123, {
encode: encodeURIComponent,
});
url.should.equal('/books/chapters/Learning%20ECMA6/123');
done();
});
Expand All @@ -1269,7 +1281,11 @@ describe('Router', function () {
embeddedRouter.use(embeddedRouter2.routes());
router.use(embeddedRouter.routes());
app.use(router.routes());
var url = router.url('chapters', { chapterName: 'Learning ECMA6', pageNumber: 123 });
var url = router.url(
'chapters',
{ chapterName: 'Learning ECMA6', pageNumber: 123 },
{ encode: encodeURIComponent }
);
url.should.equal('/books/chapters/Learning%20ECMA6/pages/123');
done();
});
Expand Down Expand Up @@ -1845,7 +1861,11 @@ describe('Router', function () {
});

it('escapes using encodeURIComponent()', function () {
var url = Router.url('/:category/:title', { category: 'programming', title: 'how to node' });
var url = Router.url(
'/:category/:title',
{ category: 'programming', title: 'how to node' },
{ encode: encodeURIComponent }
);
url.should.equal('/programming/how%20to%20node');
});

Expand Down

0 comments on commit 5fcc2ed

Please sign in to comment.