1

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?

Paul
  • 776
  • 1
  • 5
  • 18

0 Answers0