Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): jsHandle.getProperty should never resolve to null #1402

Merged
merged 1 commit into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ export class JSHandle<T = any> {
return this._context.evaluateHandle(pageFunction as any, this, ...args);
}

async getProperty(propertyName: string): Promise<JSHandle | null> {
async getProperty(propertyName: string): Promise<JSHandle> {
const objectHandle = await this.evaluateHandle((object: any, propertyName) => {
const result: any = {__proto__: null};
result[propertyName] = object[propertyName];
return result;
}, propertyName);
const properties = await objectHandle.getProperties();
const result = properties.get(propertyName) || null;
const result = properties.get(propertyName)!;
objectHandle.dispose();
return result;
}
Expand Down
12 changes: 12 additions & 0 deletions test/jshandle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ module.exports.describe = function({testRunner, expect, CHROMIUM, FFOX, WEBKIT})
const twoHandle = await aHandle.getProperty('two');
expect(await twoHandle.jsonValue()).toEqual(2);
});
it('should work with undefined, null, and empty', async({page, server}) => {
const aHandle = await page.evaluateHandle(() => ({
undefined: undefined,
null: null,
}));
const undefinedHandle = await aHandle.getProperty('undefined');
expect(String(await undefinedHandle.jsonValue())).toEqual('undefined');
const nullHandle = await aHandle.getProperty('null');
expect(await nullHandle.jsonValue()).toEqual(null);
const emptyhandle = await aHandle.getProperty('empty');
expect(String(await emptyhandle.jsonValue())).toEqual('undefined');
})
});

describe('JSHandle.jsonValue', function() {
Expand Down