fix(types): jsHandle.getProperty should never resolve to null (#1402)
Added a test to confirm that this was dead code.
This commit is contained in:
parent
5816ec53f7
commit
6dcd6a6eec
|
|
@ -67,14 +67,14 @@ export class JSHandle<T = any> {
|
||||||
return this._context.evaluateHandle(pageFunction as any, this, ...args);
|
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 objectHandle = await this.evaluateHandle((object: any, propertyName) => {
|
||||||
const result: any = {__proto__: null};
|
const result: any = {__proto__: null};
|
||||||
result[propertyName] = object[propertyName];
|
result[propertyName] = object[propertyName];
|
||||||
return result;
|
return result;
|
||||||
}, propertyName);
|
}, propertyName);
|
||||||
const properties = await objectHandle.getProperties();
|
const properties = await objectHandle.getProperties();
|
||||||
const result = properties.get(propertyName) || null;
|
const result = properties.get(propertyName)!;
|
||||||
objectHandle.dispose();
|
objectHandle.dispose();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,18 @@ module.exports.describe = function({testRunner, expect, CHROMIUM, FFOX, WEBKIT})
|
||||||
const twoHandle = await aHandle.getProperty('two');
|
const twoHandle = await aHandle.getProperty('two');
|
||||||
expect(await twoHandle.jsonValue()).toEqual(2);
|
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() {
|
describe('JSHandle.jsonValue', function() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue