From 57beb4be05248ff5286257b127a0d7755e7f84d3 Mon Sep 17 00:00:00 2001 From: Alex Anderson <191496+alxndrsn@users.noreply.github.com> Date: Sun, 10 Nov 2024 14:50:40 +0300 Subject: [PATCH] util/http: add tests for url template strings (#1282) --- test/unit/util/http.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/unit/util/http.js b/test/unit/util/http.js index 818d15d1f..0cc801f09 100644 --- a/test/unit/util/http.js +++ b/test/unit/util/http.js @@ -39,6 +39,31 @@ describe('util/http', () => { }); }); + describe('url()', () => { + const { url } = http; + + const a = 'a space'; + const b = 'funnyȩ¸iê'; + const c = '100%'; + const d = 999; + const e = { toString: () => 'e!' }; + + [ + [ url``, '' ], + [ url`/`, '/' ], + [ url`/${a}`, '/a%20space' ], + [ url`/${b}`, '/funny%C8%A9%C2%B8i%C3%AA' ], + [ url`/${c}`, '/100%25' ], + [ url`/${d}`, '/999' ], + [ url`/${e}`, '/e!' ], + [ url`/${a}/${b}?c=${c}&d=${d}&e=${e}x`, '/a%20space/funny%C8%A9%C2%B8i%C3%AA?c=100%25&d=999&e=e!x' ], + ].forEach(([ actual, expected ]) => { + it(`should correctly encode ${expected}`, () => { + actual.should.equal(expected); + }); + }); + }); + describe('urlPathname', () => { const { urlPathname } = http; it('should return the pathname part of a url', () => {