[QUESTION] How does one mock zip.js in Jest tests?
remarkablemark opened this issue · 2 comments
remarkablemark commented
I'm using zip.js
in my frontend project and I'm trying to write Jest tests but they're failing with:
ReferenceError: TransformStream is not defined
> 1 | import { BlobReader, BlobWriter, ZipWriter } from '@zip.js/zip.js';
| ^
I'm using jsdom
for my test environment.
Is the best way to resolve this is to mock the node module? I have seen other projects provide a mock file for Jest.
gildas-lormeau commented
If the web steam API is not available, then you should able to circumvent this issue by importing this module before running the tests: https://www.npmjs.com/package/web-streams-polyfill
remarkablemark commented
Thanks! I ended up creating a module mock for the package:
mkdir -p __mocks__/@zip.js/
echo "module.exports = {};" > __mocks__/@zip.js/zip.js.js