13

I'm trying to get description of a page with Puppeteer, I have a high order function that provides the page object to this function :

export const checkDescription = async page => {
  const metaDescription = await page.$eval(
    'meta[name="description"]',
    description => description.getAttribute("content")
  );
  return metaDescription;
};

the function works as expected. Then, I'm using Jest to run a test.

const testDescription = await withPage(checkDescription)(URL);
expect(typeof testDescription).toBe("string");

I have the following err:

  Error: Evaluation failed: ReferenceError: cov_4kq3tptqc is not defined
      at __puppeteer_evaluation_script__:2:41
      at ExecutionContext.evaluateHandle 
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)
    -- ASYNC --
      at ExecutionContext.<anonymous> 
      at ExecutionContext.evaluate
      at ExecutionContext.<anonymous> 
      at ElementHandle.$eval
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)
    -- ASYNC --

If I just paste the function in the jest file, then it works as expected

Elena
  • 569
  • 3
  • 7
  • 19

2 Answers2

9

If you need to collect the coverage, it can be fixed by adding /* istanbul ignore next */ before browser contexted functions (lines with .eval) to prevent istanbul coverage injects.

oneralon
  • 91
  • 1
  • 1
6

In puppeteer, while running tests, istanbul was inserting the following :

 /* istanbul ignore next */cov_4kq3tptqc.f[7]++;
                    cov_4kq3tptqc.s[19]++;

Was fixed by adding config.collectCoverage = false; to the jest.config

Elena
  • 569
  • 3
  • 7
  • 19
  • Not only does `config.collectCoverage = false` fixes break the above error but also the breakpoint of vscode in debugging mode (typescript) now works when – fredtma Mar 10 '20 at 11:41