mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Created query helper test
This commit is contained in:
parent
4642e07fd3
commit
f5d03ed3a2
1 changed files with 25 additions and 0 deletions
25
test/utils/helpers/query.test.ts
Normal file
25
test/utils/helpers/query.test.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { parseQuery, stringifyQuery } from '../../../src/utils/helpers/query';
|
||||||
|
|
||||||
|
describe('query', () => {
|
||||||
|
describe('parseQuery', () => {
|
||||||
|
it.each([
|
||||||
|
[ '', {}],
|
||||||
|
[ 'foo=bar', { foo: 'bar' }],
|
||||||
|
[ '?foo=bar', { foo: 'bar' }],
|
||||||
|
[ '?foo=bar&baz=123', { foo: 'bar', baz: '123' }],
|
||||||
|
])('parses query string as expected', (queryString, expectedResult) => {
|
||||||
|
expect(parseQuery(queryString)).toEqual(expectedResult);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('stringifyQuery', () => {
|
||||||
|
it.each([
|
||||||
|
[{}, '' ],
|
||||||
|
[{ foo: 'bar' }, 'foo=bar' ],
|
||||||
|
[{ foo: 'bar', baz: '123' }, 'foo=bar&baz=123' ],
|
||||||
|
[{ bar: 'foo', list: [ 'one', 'two' ] }, encodeURI('bar=foo&list[]=one&list[]=two') ],
|
||||||
|
])('stringifies query as expected', (queryObj, expectedResult) => {
|
||||||
|
expect(stringifyQuery(queryObj)).toEqual(expectedResult);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue