test: utils.params

This commit is contained in:
Barış Soner Uşaklı
2021-11-30 18:36:18 -05:00
parent f72af319fb
commit 7b99dc46eb
2 changed files with 9 additions and 1 deletions

View File

@@ -662,7 +662,7 @@
if (!hash[key]) { if (!hash[key]) {
hash[key] = value; hash[key] = value;
} else { } else {
if (!$.isArray(hash[key])) { if (!Array.isArray(hash[key])) {
hash[key] = [hash[key]]; hash[key] = [hash[key]];
} }
hash[key].push(value); hash[key].push(value);

View File

@@ -318,6 +318,14 @@ describe('Utility Methods', () => {
done(); done();
}); });
it('should get url params as arrays', (done) => {
const params = utils.params({ url: 'http://nodebb.org?foo=1&bar=test&herp[]=2&herp[]=3' });
assert.equal(params.foo, 1);
assert.equal(params.bar, 'test');
assert.deepStrictEqual(params.herp, [2, 3]);
done();
});
it('should get a single param', (done) => { it('should get a single param', (done) => {
assert.equal(utils.param('somekey'), undefined); assert.equal(utils.param('somekey'), undefined);
done(); done();