由于未实现.getContext(),单元测试引发错误 [英] unit test raises error because of .getContext() is not implemented
问题描述
我正在使用Jest为使用画布元素的组件编写测试.运行如下所示的测试时,我总是收到错误消息.
I am writing tests using Jest for components that use canvas elements. I keep getting an error when I run my tests that looks like this.
Error: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package)
据我了解,Jest使用jsdom进行测试,并且如果您安装canvas或canvas预构建的软件包,则jsdom与canvas兼容.
From my understanding Jest uses jsdom for its testing and that jsdom is compatible with canvas if you install the canvas or canvas-prebuilt packages.
我尝试安装这些软件包中的每一个,但它们均未解决该错误.我认为唯一可能出错的是jsdom无法找到canvas或canvas预构建的包.有谁知道解决此错误或测试看看jsdom是否正在寻找其他软件包的方法?非常感谢!
I have tried installing each of these packages and neither of them have resolved the error. The only thing that I think could be going wrong is that jsdom cannot find the canvas or canvas-prebuilt packages. Does anyone know a way to fix this error or test to see if jsdom is finding the other packages? Thanks a lot!
推荐答案
您可以在 查看全文