Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(fetch): filter out undefined `params` (#34654)
Dmitry Gozman8d751cfe507b
diff --git a/packages/playwright-core/src/client/fetch.ts b/packages/playwright-core/src/client/fetch.tsindex 58928532ac..efacce417d 100644--- a/packages/playwright-core/src/client/fetch.ts+++ b/packages/playwright-core/src/client/fetch.ts@@ -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;}diff --git a/tests/library/browsercontext-fetch.spec.ts b/tests/library/browsercontext-fetch.spec.tsindex 38848dd497..f23b59f97c 100644--- a/tests/library/browsercontext-fetch.spec.ts+++ b/tests/library/browsercontext-fetch.spec.ts@@ -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 }) => {