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


基础教程推荐
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01