-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added test to show how old queryParse is not necessary
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
}); | ||
}); |