From 04e5c889973432c6163a8539cdec23c0e8726bff Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Thu, 7 Apr 2022 18:06:12 +0200 Subject: [PATCH] fix: ignore favicon requests in page.spec event handler tests (#8208) --- test/page.spec.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/test/page.spec.ts b/test/page.spec.ts index 68fb6d87419f4..882e0af9fca7f 100644 --- a/test/page.spec.ts +++ b/test/page.spec.ts @@ -127,14 +127,20 @@ describe('Page', function () { const { page, server } = getTestState(); const handler = sinon.spy(); - page.on('response', handler); + const onResponse = (response) => { + // Ignore default favicon requests. + if (!response.url().endsWith('favicon.ico')) { + handler(); + } + }; + page.on('response', onResponse); await page.goto(server.EMPTY_PAGE); expect(handler.callCount).toBe(1); - page.off('response', handler); + page.off('response', onResponse); await page.goto(server.EMPTY_PAGE); // Still one because we removed the handler. expect(handler.callCount).toBe(1); - page.on('response', handler); + page.on('response', onResponse); await page.goto(server.EMPTY_PAGE); // Two now because we added the handler back. expect(handler.callCount).toBe(2); @@ -144,14 +150,21 @@ describe('Page', function () { const { page, server } = getTestState(); const handler = sinon.spy(); - page.on('request', handler); + const onResponse = (response) => { + // Ignore default favicon requests. + if (!response.url().endsWith('favicon.ico')) { + handler(); + } + }; + + page.on('request', onResponse); await page.goto(server.EMPTY_PAGE); expect(handler.callCount).toBe(1); - page.off('request', handler); + page.off('request', onResponse); await page.goto(server.EMPTY_PAGE); // Still one because we removed the handler. expect(handler.callCount).toBe(1); - page.on('request', handler); + page.on('request', onResponse); await page.goto(server.EMPTY_PAGE); // Two now because we added the handler back. expect(handler.callCount).toBe(2);