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
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
Share Improve this question asked Mar 21, 2019 at 1:00 ElenaElena 6493 gold badges9 silver badges19 bronze badges 3 |3 Answers
Reset to default 10If 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
Placing /* istanbul ignore next */ within the evaluate function resolved the problem effectively.
Didn't work:
/* istanbul ignore next */
const result = await page.evaluate((el, attr) => el.getAttribute(attr), el, attr)
Worked:
const result = await page.evaluate(/* istanbul ignore next */(el, attr) => el.getAttribute(attr), el, attr)
withPage
? – Julien TASSIN Commented Mar 22, 2019 at 20:36