0

I'm running jest tests using puppeteer. On some of them I manually add some specific css styles and other tweaks like the following:

  const content = `
    *,
    *::after,
    *::before {
        transition-delay: 0s !important;
        transition-duration: 0s !important;
        animation-delay: -0.0001s !important;
        animation-duration: 0s !important;
        animation-play-state: paused !important;
        caret-color: transparent !important;
    }`;

  page.addStyleTag({ content });

as well as some listeners. I would like to remove everything by "resetting" the page to its pristine status for each test. What's the best way to accomplish this?

Bertuz
  • 2,390
  • 3
  • 25
  • 50
  • Any reason you wouldn't just create a new page? – Alan Friedman Jul 16 '22 at 18:15
  • it could be an option, but to be honest I'm not that sure that in that case I can use the global `page` offered by jest-environment-puppeteer. Maybe I can overwrite it when requesting a new page and that's it. https://github.com/opticpower/jest-environment-puppeteer#globalpage. I guess you're suggesting something like `await page.close(); global.page = await page.browser().newPage();` – Bertuz Jul 16 '22 at 23:07

0 Answers0