Skip to content

Commit

Permalink
test: added test to show how old queryParse is not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-micah committed Dec 10, 2024
1 parent a198f6d commit 9af171e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions apps/storefront/tests/shared/request.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// TODO: Old logic - remove
const queryParse = <T>(query: T): string => {
let queryText = '';

Object.keys(query || {}).forEach((key: string) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
queryText += `${key}=${(query as any)[key]}&`;
});
return queryText.slice(0, -1);
};

describe('queryParse', () => {
it('should stringify objects', () => {
const params = {
foo: 'bar',
hello: 'world',
};
const output = queryParse(params);

expect(output).toMatchInlineSnapshot(`"foo=bar&hello=world"`);

const newLogic = new URLSearchParams(params);

expect(newLogic.toString()).toMatchInlineSnapshot(`"foo=bar&hello=world"`);

expect(output).toMatch(newLogic.toString());
});
});

0 comments on commit 9af171e

Please sign in to comment.