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
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With