From 9f1b2f68bf5de8043d161aa179f332dd01bc01f4 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Tue, 23 Mar 2021 11:44:26 +0800 Subject: [PATCH] test(resize): add a screenshot resize test (#5907) --- test/elementhandle-screenshot.spec.ts | 14 ++++++++++++++ test/page-screenshot.spec.ts | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/test/elementhandle-screenshot.spec.ts b/test/elementhandle-screenshot.spec.ts index 5c9741f53919b..66ffb55733914 100644 --- a/test/elementhandle-screenshot.spec.ts +++ b/test/elementhandle-screenshot.spec.ts @@ -401,4 +401,18 @@ describe('element screenshot', (suite, parameters) => { const buffer = await elementHandle.screenshot({ path: outputPath, type: 'jpeg' }); expect([buffer[0], buffer[1], buffer[2]]).toEqual([0xFF, 0xD8, 0xFF]); }); + + it('should not issue resize event', async ({page, server}) => { + await page.goto(server.PREFIX + '/grid.html'); + let resizeTriggered = false; + await page.exposeFunction('resize', () => { + resizeTriggered = true; + }); + await page.evaluate(() => { + window.addEventListener('resize', () => (window as any).resize()); + }); + const elementHandle = await page.$('.box:nth-of-type(3)'); + await elementHandle.screenshot(); + expect(resizeTriggered).toBeFalsy(); + }); }); diff --git a/test/page-screenshot.spec.ts b/test/page-screenshot.spec.ts index e60ea1ed22051..e0af838cf87cf 100644 --- a/test/page-screenshot.spec.ts +++ b/test/page-screenshot.spec.ts @@ -341,4 +341,17 @@ describe('page screenshot', (suite, { browserName, headful }) => { expect(pixel(0, 8339).r).toBeLessThan(128); expect(pixel(0, 8339).b).toBeGreaterThan(128); }); + + it('should not issue resize event', async ({page, server}) => { + await page.goto(server.PREFIX + '/grid.html'); + let resizeTriggered = false; + await page.exposeFunction('resize', () => { + resizeTriggered = true; + }); + await page.evaluate(() => { + window.addEventListener('resize', () => (window as any).resize()); + }); + await page.screenshot(); + expect(resizeTriggered).toBeFalsy(); + }); });