2020-12-20 21:51:43 +03:00
|
|
|
import { parseQuery, stringifyQuery } from '../../../src/utils/helpers/query';
|
|
|
|
|
|
|
|
describe('query', () => {
|
|
|
|
describe('parseQuery', () => {
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
['', {}],
|
|
|
|
['foo=bar', { foo: 'bar' }],
|
|
|
|
['?foo=bar', { foo: 'bar' }],
|
|
|
|
['?foo=bar&baz=123', { foo: 'bar', baz: '123' }],
|
2020-12-20 21:51:43 +03:00
|
|
|
])('parses query string as expected', (queryString, expectedResult) => {
|
|
|
|
expect(parseQuery(queryString)).toEqual(expectedResult);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('stringifyQuery', () => {
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
[{}, ''],
|
|
|
|
[{ foo: 'bar' }, 'foo=bar'],
|
|
|
|
[{ foo: 'bar', baz: '123' }, 'foo=bar&baz=123'],
|
|
|
|
[{ bar: 'foo', list: ['one', 'two'] }, encodeURI('bar=foo&list[]=one&list[]=two')],
|
2020-12-20 21:51:43 +03:00
|
|
|
])('stringifies query as expected', (queryObj, expectedResult) => {
|
|
|
|
expect(stringifyQuery(queryObj)).toEqual(expectedResult);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|