admin管理员组文章数量:1180551
I type:
npm test
and I get:
It's interesting to note that the import statement works inside the BootScene.test.js file but it doesn't work in the imported file.
I focused on the import statement not working under JEst. So I thought maybe it has something to do with Ecma Script version jest uses. So I tried this solution but the error persists.
This is the repo/branch of this question.
When I type npm start
. Everything flows swiftly and with no errors.
I type:
npm test
and I get:
It's interesting to note that the import statement works inside the BootScene.test.js file but it doesn't work in the imported file.
I focused on the import statement not working under JEst. So I thought maybe it has something to do with Ecma Script version jest uses. So I tried this solution but the error persists.
This is the repo/branch of this question.
When I type npm start
. Everything flows swiftly and with no errors.
3 Answers
Reset to default 27The error occurs because jestdom is not able add canvas, which we need to do. For me this happened because I was using lottiefiles for the application.
Here is how I fixed it for my react application.
Install jest-canvas-mock as below .
npm i jest-canvas-mock
Then go to setup file like setup-tests.js and import jest-canvas as below .
import "jest-canvas-mock";
Now run test, you should not get errors any more.
I solved it by following this instructions.
Thanks CherryDt.
Installing npm i jest-canvas-mock and Importing import "jest-canvas-mock" in set-up file; works for me
版权声明:本文标题:javascript - Jest import statement: 'TypeError: Cannot set property 'fillStyle' of null' - Stack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738133748a2065353.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
phaser
module (implying it was in fact imported), as you can see from the call stack. Try googlingphaser Cannot set property fillStyle of null
and you'll find several GitHub issues pointing towards a solution of installingcanvas-prebuilt
and/or installing and requiringjest-canvas-mock
before your other imports. – CherryDT Commented Aug 2, 2020 at 19:15