mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: ignore favicon requests in page.spec event handler tests (#8208)
This commit is contained in:
parent
0955225b51
commit
04e5c88997
@ -127,14 +127,20 @@ describe('Page', function () {
|
|||||||
const { page, server } = getTestState();
|
const { page, server } = getTestState();
|
||||||
|
|
||||||
const handler = sinon.spy();
|
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);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
expect(handler.callCount).toBe(1);
|
expect(handler.callCount).toBe(1);
|
||||||
page.off('response', handler);
|
page.off('response', onResponse);
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
// Still one because we removed the handler.
|
// Still one because we removed the handler.
|
||||||
expect(handler.callCount).toBe(1);
|
expect(handler.callCount).toBe(1);
|
||||||
page.on('response', handler);
|
page.on('response', onResponse);
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
// Two now because we added the handler back.
|
// Two now because we added the handler back.
|
||||||
expect(handler.callCount).toBe(2);
|
expect(handler.callCount).toBe(2);
|
||||||
@ -144,14 +150,21 @@ describe('Page', function () {
|
|||||||
const { page, server } = getTestState();
|
const { page, server } = getTestState();
|
||||||
|
|
||||||
const handler = sinon.spy();
|
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);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
expect(handler.callCount).toBe(1);
|
expect(handler.callCount).toBe(1);
|
||||||
page.off('request', handler);
|
page.off('request', onResponse);
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
// Still one because we removed the handler.
|
// Still one because we removed the handler.
|
||||||
expect(handler.callCount).toBe(1);
|
expect(handler.callCount).toBe(1);
|
||||||
page.on('request', handler);
|
page.on('request', onResponse);
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
// Two now because we added the handler back.
|
// Two now because we added the handler back.
|
||||||
expect(handler.callCount).toBe(2);
|
expect(handler.callCount).toBe(2);
|
||||||
|
Loading…
Reference in New Issue
Block a user