Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: JSHandle.getProperties() returns own properties only (#42749)

Dmitry Gozmanf1ea64bd0062
diff --git a/tests/page/jshandle-properties.spec.ts b/tests/page/jshandle-properties.spec.ts
index 1b959e762d..8819cc7704 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('<div id=d><span>a</span><span>b</span></div>');
+ 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(`<div>Hello</div>`);
const handle = await page.evaluateHandle(() => ({ body: document.body }));