gpt4 book ai didi

javascript - 开 Jest 导入语句 : 'TypeError: Cannot set property ' fillStyle' of null'

转载 作者:行者123 更新时间:2023-12-05 00:34:25 27 4
gpt4 key购买 nike

我输入:

npm test
我得到:
enter image description here
有趣的是,import 语句在 BootScene.test.js 文件中有效,但在导入的文件中无效。
我专注于在 JEst 下不起作用的导入语句。所以我想这可能与开 Jest 使用的 Ecma Script 版本有关。所以我尝试了 this解决方案,但错误仍然存​​在。
This是这个问题的 repo /分支。
当我输入 npm start .一切都快速流动,没有错误。

最佳答案

发生错误是因为 jestdom 无法添加我们需要做的 Canvas 。对我来说,发生这种情况是因为我在应用程序中使用了 lottiefiles。
这是我为我的 react 应用程序修复它的方法。
安装 jest-canvas-mock 如下。

 npm i jest-canvas-mock
然后转到 setup-tests.js 之类的设置文件并导入 jest-canvas,如下所示。
import "jest-canvas-mock";
现在运行测试,您应该不会再出现错误。

关于javascript - 开 Jest 导入语句 : 'TypeError: Cannot set property ' fillStyle' of null',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63219552/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com