Using Jest with Puppeteer : Evaluation failed: ReferenceError: cov_4kq3tptqc is not defined(将 Jest 与 Puppeteer 一起使用:评估失败:ReferenceError: cov_4kq3tptqc is not defined)
问题描述
我正在尝试使用 Puppeteer 获取页面的描述,我有一个高阶函数,为该函数提供页面对象:
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;
};
该功能按预期工作.然后,我正在使用 Jest 运行测试.
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");
我有以下错误:
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 --
如果我只是将函数粘贴到 jest 文件中,那么它会按预期工作
If I just paste the function in the jest file, then it works as expected
推荐答案
如果需要收集覆盖率,可以通过在浏览器上下文函数前添加 /* istanbul ignore next */
来修复(带有 .eval
) 的行以防止伊斯坦布尔覆盖注入.
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.
这篇关于将 Jest 与 Puppeteer 一起使用:评估失败:ReferenceError: cov_4kq3tptqc is not defined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 Jest 与 Puppeteer 一起使用:评估失败:ReferenceError: cov_4kq3tptqc is not defined


- Flexslider 箭头未正确显示 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Fetch API 如何获取响应体? 2022-01-01