Jest-puppeteer: Request is already handled!

Created on 19 Oct 2018  路  6Comments  路  Source: smooth-code/jest-puppeteer

Error Information

Request is already handled!

To Reproduce

describe('Test', () => {
    beforeEach(async () => {
        jest.setTimeout = 30000;
        await page.setRequestInterception(true);
        page.on('request', request => {
            request.continue();
        })
        await page.goto('https://www.google.com/');
    });

    afterEach(async () => {
        page.removeListener("request", () => {});
    })

    it('case1:...', async () => {
        await expect(page).toMatch('Google');
    })

    it('case2:...', async () => {
        await expect(page).toMatch('Google');
    })

});

Expected behavior

I want to modify some response data in every testcase, so help me plz.

Most helpful comment

Looks like this issue should be reopened, it's a really weird behaviour.

All 6 comments

ah...I've got it fixed by doing this:

beforeEach(async () => {
        jest.setTimeout = 30000;
        page = await browser.newPage();
        await page.setRequestInterception(true);
        page.on('request', request => {
            request.continue();
        })
        await page.goto('https://www.google.com/');
    });

Is this the actual solution though? Why do we need to create a new page, when each test run should start a new page all the time?

@neoziro

If this was the only alternative, how can we add this to our global setup and teardowns so we don't have to do it for each test that we need it to?

Looks like this issue should be reopened, it's a really weird behaviour.

Maybe @gregberge can re-open this issue? Or @songguohfut

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Pyrolistical picture Pyrolistical  路  6Comments

Greg-oliver99 picture Greg-oliver99  路  4Comments

alexander-elgin picture alexander-elgin  路  4Comments

undrafted picture undrafted  路  4Comments

ifiokjr picture ifiokjr  路  5Comments