fix(fetch): filter out undefined `params` (#34654)
This commit is contained in:
parent
365f411548
commit
8d751cfe50
|
@ -416,8 +416,10 @@ function objectToArray(map?: { [key: string]: any }): NameValue[] | undefined {
|
|||
if (!map)
|
||||
return undefined;
|
||||
const result = [];
|
||||
for (const [name, value] of Object.entries(map))
|
||||
result.push({ name, value: String(value) });
|
||||
for (const [name, value] of Object.entries(map)) {
|
||||
if (value !== undefined)
|
||||
result.push({ name, value: String(value) });
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -1183,7 +1183,7 @@ it('should send secure cookie over http for localhost', async ({ page, server })
|
|||
expect(serverRequest.headers.cookie).toBe('a=v');
|
||||
});
|
||||
|
||||
it('should accept bool and numeric params', async ({ page, server }) => {
|
||||
it('should accept bool and numeric params and filter out undefined', async ({ page, server }) => {
|
||||
let request;
|
||||
const url = new URL(server.EMPTY_PAGE);
|
||||
url.searchParams.set('str', 's');
|
||||
|
@ -1200,6 +1200,7 @@ it('should accept bool and numeric params', async ({ page, server }) => {
|
|||
'num': 10,
|
||||
'bool': true,
|
||||
'bool2': false,
|
||||
'none': undefined,
|
||||
}
|
||||
});
|
||||
const params = new URLSearchParams(request!.url.substr(request!.url.indexOf('?')));
|
||||
|
@ -1207,6 +1208,7 @@ it('should accept bool and numeric params', async ({ page, server }) => {
|
|||
expect(params.get('num')).toEqual('10');
|
||||
expect(params.get('bool')).toEqual('true');
|
||||
expect(params.get('bool2')).toEqual('false');
|
||||
expect(params.has('none')).toBe(false);
|
||||
});
|
||||
|
||||
it('should abort requests when browser context closes', async ({ contextFactory, server }) => {
|
||||
|
|
Loading…
Reference in New Issue