2

I am wondering if it is possible in Jest to skip one or more tests in a suite based on the value of a variable used in the beforeEach function.

My code:

  let errLoadingData = false;

  beforeEach(async () => {
    await page.goto('myurl.com');
    try {
      await waitForSelector('error-banner');
    } catch (error) {
      errLoadingData = true;
      throw new Error(
        'Myurl page displaying error to user.',
      );
    }
  });

  test('Visit myurl page', async () => {
    // wait for and click elements on myurl page
    .
    .
    .
  }

I would like to not run Visit myurl page if errLoadingData = true.

Thanks in advance!

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Marlo
  • 490
  • 3
  • 7
  • 21
  • Puppeteer is not a test framework. To skip or run a test should be handled by the test framework e.g. Mocha/Jest (whichever you are using). – yeniv Nov 26 '20 at 08:26
  • @yeniv Thanks, I am using Jest. Edited post to reflect that. – Marlo Nov 27 '20 at 17:17
  • Jest provides option to skip tests: [check here](https://jestjs.io/docs/en/api#testskipname-fn) – yeniv Dec 01 '20 at 13:45
  • @yeniv I know about this option; I am asking if there is a way to conditionally skip a test based on a certain variable. I don't see that here, so I guess it's not possible. – Marlo Dec 03 '20 at 15:57

0 Answers0