From f5d03ed3a2071c6a135157ff5dbee925f941f46f Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 20 Dec 2020 19:51:43 +0100 Subject: [PATCH] Created query helper test --- test/utils/helpers/query.test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/utils/helpers/query.test.ts diff --git a/test/utils/helpers/query.test.ts b/test/utils/helpers/query.test.ts new file mode 100644 index 00000000..90969bce --- /dev/null +++ b/test/utils/helpers/query.test.ts @@ -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); + }); + }); +});