-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Add tests for encodeParamsToSearchParams
- Loading branch information
1 parent
10fbdb2
commit 0ca805c
Showing
4 changed files
with
25 additions
and
50 deletions.
There are no files selected for viewing
36 changes: 12 additions & 24 deletions
36
packages/@ackee/antonio-core/src/modules/request/utils/url/__tests__/searchParams.test.ts
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 |
---|---|---|
@@ -1,40 +1,28 @@ | ||
import { getValidSearchParams, encodeParamsToSearchParams } from '../searchParams'; | ||
import { encodeParamsToSearchParams } from '../searchParams'; | ||
|
||
describe('getValidSearchParams', () => { | ||
it('returns params without null, undefined or empty string', () => { | ||
const params = new URLSearchParams({ | ||
a: 'null', | ||
b: 'undefined', | ||
c: '', | ||
d: 'foo', | ||
}); | ||
|
||
const validParams = getValidSearchParams(params); | ||
|
||
expect(validParams.has('d')).toBe(true); | ||
expect(Array.from(validParams.entries()).length).toBe(1); | ||
}); | ||
}); | ||
|
||
describe.only('encodeParamsToSearchParams', () => { | ||
describe('encodeParamsToSearchParams', () => { | ||
it(`returns undefined if undefined params received`, () => { | ||
expect(encodeParamsToSearchParams()).toBe(undefined); | ||
expect(encodeParamsToSearchParams()).toBeInstanceOf(URLSearchParams); | ||
}); | ||
|
||
it(`returns received params if they're instace of URLSearchParams`, () => { | ||
const params = new URLSearchParams(); | ||
expect(encodeParamsToSearchParams(params)).toBe(params); | ||
}); | ||
|
||
// TODO: | ||
it.skip(`encodes object literal to an instance of URLSearchParams`, () => { | ||
it(`encodes object literal to an instance of URLSearchParams`, () => { | ||
const params = { | ||
a: 1, | ||
b: ['a', 'b'], | ||
b: [1, 2], | ||
c: 'foo', | ||
d: true, | ||
}; | ||
|
||
// TODO: continue here | ||
// const result = encodeParamsToSearchParams(params); | ||
const result = encodeParamsToSearchParams(params); | ||
|
||
expect(result.get('a')).toBe('1'); | ||
expect(result.getAll('b')).toEqual(['1', '2']); | ||
expect(result.get('c')).toBe('foo'); | ||
expect(result.get('d')).toBe('true'); | ||
}); | ||
}); |
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
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
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