From 4a6a1a891761b68c03e80996c211a14dc6341383 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Tue, 15 Sep 2026 12:58:23 +0100 Subject: [PATCH] test: JSHandle.getProperties() returns own properties only --- tests/page/jshandle-properties.spec.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/page/jshandle-properties.spec.ts b/tests/page/jshandle-properties.spec.ts index 1b959e762d322..8819cc7704072 100644 --- a/tests/page/jshandle-properties.spec.ts +++ b/tests/page/jshandle-properties.spec.ts @@ -74,7 +74,7 @@ it('getProperties should return empty map for non-objects', async ({ page }) => expect(properties.size).toBe(0); }); -it('getProperties should return even non-own properties', async ({ page }) => { +it('getProperties should return properties inhertied from super class', async ({ page }) => { const aHandle = await page.evaluateHandle(() => { class A { a: string; @@ -96,6 +96,26 @@ it('getProperties should return even non-own properties', async ({ page }) => { expect(await properties.get('b').jsonValue()).toBe('2'); }); +it('getProperties should return own enumerable properties only', { + annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42651' }, +}, async ({ page }) => { + const aHandle = await page.evaluateHandle(() => { + class A { + constructor() { + (this as any).own = 1; + Object.defineProperty(this, 'ownHidden', { value: 2, enumerable: false }); + } + } + (A.prototype as any).inherited = 3; + return new A(); + }); + expect([...(await aHandle.getProperties()).keys()]).toEqual(['own']); + + await page.setContent('
ab
'); + const collection = await page.evaluateHandle(() => document.querySelector('#d').children); + expect([...(await collection.getProperties()).keys()]).toEqual(['0', '1']); +}); + it('getProperties should work with elements', async ({ page }) => { await page.setContent(`
Hello
`); const handle = await page.evaluateHandle(() => ({ body: document.body }));