可以使用PDFMake的测试组件

发布于 2025-02-09 21:52:19 字数 588 浏览 2 评论 0原文

我想测试使用PDFMake的组件。当我将组件导入到测试文件中时,我会收到错误。

TypeError: Cannot read properties of undefined (reading 'pdfMake')

  20 | import DirectionsBusIcon from "@mui/icons-material/DirectionsBus";
  21 | import pdfMake from "pdfmake/build/pdfmake";
> 22 | import pdfFonts from "pdfmake/build/vfs_fonts";
     | ^
  23 | pdfMake.vfs = pdfFonts.pdfMake.vfs;

在PDFMake的页面上,他们提到了

“如果您使用的是汇总,并且在vfs_fonts.js错误上无法读取属性'pdfmake',则将其添加到汇总配置中:“

moduleContext: {
  './node_modules/pdfmake/build/vfs_fonts.js': 'window',
},

我如何为此配置开玩笑?

I want to test a component that uses pdfMake. When I import the component into my test file I get the error.

TypeError: Cannot read properties of undefined (reading 'pdfMake')

  20 | import DirectionsBusIcon from "@mui/icons-material/DirectionsBus";
  21 | import pdfMake from "pdfmake/build/pdfmake";
> 22 | import pdfFonts from "pdfmake/build/vfs_fonts";
     | ^
  23 | pdfMake.vfs = pdfFonts.pdfMake.vfs;

On the page for pdfMake they mention this

"If you are using rollup, and a Cannot read property ‘pdfMake’ of undefined at vfs_fonts.js error is thrown, add this to rollup config:"

moduleContext: {
  './node_modules/pdfmake/build/vfs_fonts.js': 'window',
},

How can I configure jest for that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文