Jest-puppeteer: Reset browser state between tests?

Created on 8 Jun 2018  路  6Comments  路  Source: smooth-code/jest-puppeteer

Hello, I noticed that the state of the browser/page remains between tests (it).
AFAIK the common practice is to have each it independent so running a single it or all of them are guaranteed to give the same result.

I can imagine though that one could want to execute multiple it to cover a single scenario with a describe. So I'm curious to know if the current behaviour is actually intended.

Most helpful comment

Could you show an example of how to reset the page between tests?

Is it sufficient to just do:

beforeEach(async () => {
  await page.close();
  page = await context.newPage();
});

It looks like different things are setup on page based on settings.
https://github.com/smooth-code/jest-puppeteer/blob/cc9bbfa493349cc88273120996e713523cf86714/packages/jest-environment-puppeteer/src/PuppeteerEnvironment.js#L61-L63

It seems like it would be easier to have a setting in jest-puppeteer.config.js that will reset page with the same configuration between tests.

All 6 comments

I prefer to let the user decide, you can put a "before" or a "beforeEach" and reset what you need.

Could you show an example of how to reset the page between tests?

Is it sufficient to just do:

beforeEach(async () => {
  await page.close();
  page = await context.newPage();
});

It looks like different things are setup on page based on settings.
https://github.com/smooth-code/jest-puppeteer/blob/cc9bbfa493349cc88273120996e713523cf86714/packages/jest-environment-puppeteer/src/PuppeteerEnvironment.js#L61-L63

It seems like it would be easier to have a setting in jest-puppeteer.config.js that will reset page with the same configuration between tests.

Or maybe provide a jestPuppeteer.resetPage() function that could easily be called to reset to the same configuration?

@UziTech yes I think it is a good idea, can you open another issue to describe the feature?

Has this feature been created.. I am having the same issues in an angular app
@UziTech

Was this page helpful?
0 / 5 - 0 ratings

Related issues

melissachang picture melissachang  路  6Comments

ifiokjr picture ifiokjr  路  5Comments

Pyrolistical picture Pyrolistical  路  6Comments

binhxn picture binhxn  路  6Comments

FezVrasta picture FezVrasta  路  4Comments