test: add failing test for eval with overridden Array.toJSON (#6766)

This commit is contained in:
Yury Semikhatsky 2021-05-26 23:02:21 +00:00 committed by GitHub
parent fb3c6e50d4
commit 3b220e50ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -550,6 +550,15 @@ it('should not use toJSON when evaluating', async ({ page }) => {
expect(result).toEqual({ data: 'data', toJSON: {} });
});
it('should not use Array.prototype.toJSON when evaluating', async ({ page, browserName }) => {
it.fixme(browserName === 'firefox', 'https://github.com/microsoft/playwright/issues/6750');
const result = await page.evaluate(() => {
(Array.prototype as any).toJSON = () => 'busted';
return [1, 2, 3];
});
expect(result).toEqual([1,2,3]);
});
it('should not use toJSON in jsonValue', async ({ page }) => {
const resultHandle = await page.evaluateHandle(() => ({ toJSON: () => 'string', data: 'data' }));
expect(await resultHandle.jsonValue()).toEqual({ data: 'data', toJSON: {} });