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


基础教程推荐
- Bokeh Div文本对齐 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01