Jest-puppeteer: Request is already handled!

Created on 21 Jan 2020  路  3Comments  路  Source: smooth-code/jest-puppeteer

Note: Reposting this from https://github.com/smooth-code/jest-puppeteer/issues/147 since we'd like this issue to be opened again.

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.

stale 馃挰

Most helpful comment

I've managed to get around this by using resetPage:

  beforeEach(async () => {
    await jestPuppeteer.resetPage();
    await page.goto('http://localhost:5001');
  });

I don't know if it makes a difference with your case but i'm using the jest command line option --runInBand.

All 3 comments

Current fix is...

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/');
    });

However we'd like to avoid having to do await browser.newPage() every time.

I've managed to get around this by using resetPage:

  beforeEach(async () => {
    await jestPuppeteer.resetPage();
    await page.goto('http://localhost:5001');
  });

I don't know if it makes a difference with your case but i'm using the jest command line option --runInBand.

@counterbeing I'll try and use this and report back.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

melissachang picture melissachang  路  6Comments

macabeus picture macabeus  路  4Comments

lakesare picture lakesare  路  3Comments

aheissenberger picture aheissenberger  路  5Comments

songguohfut picture songguohfut  路  6Comments