Error when use lottie-web and run test reactjs with Jest.
See original GitHub issueI’m using lottie-web library in my reactjs project. When I run test, initially I got error:
Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package)

I’ve reseached and fixed it by install jest-canvas-mock:
"setupFiles": [
"<rootDir>/tests/setupJest.ts",
"jest-canvas-mock"
],
But I’ve got new error: Error: connect ECONNREFUSED 127.0.0.1:80 😦

Issue Analytics
- State:
- Created 3 years ago
- Comments:8
Top Results From Across the Web
React Jest Tests Failing Using Lottie.js Solved | Rob Marshall
The error is caused by the import of the lottie-react package. After some research it seemed that Jest is not set up to...
Read more >Lottie mocking is not working in react-testing-library [closed]
When I tried to run test cases I am getting the following error: TypeError: Cannot set property 'fillStyle' of null for line: import...
Read more >lottie-react - npm
Start using lottie-react in your project by running `npm i ... Known Vulnerabilities Coverage Status Tested with jest GitHub license.
Read more >React Lottie Play on hover tutorial - CodeSandbox
import lottie from "lottie-web";. function App() {. const container = useRef(null);. useEffect(() => {. lottie.loadAnimation({. container: container.current ...
Read more >[Solved]-Unexpected token < in JSON at position 0 vuejs-Vue.js
Instead of using path use animationData and just set the animation object directly (instead of ... Unexpected token 'import' error while running Jest...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Instead of mocking the module, you can also try importing
jest-canvas-mockon your setupTests filehi, I think that for testing purposes you’d probably want to mock the lottie library. Otherwise it will try to load the animation through the network, which is probably what is happening in this case.