当我运行单元测试时,我发现以下错误:
Error: Not implemented: HTMLCanvasElement.prototype.getContext
(without installing the canvas npm package)
要解决此问题,首先必须安装jest-canvas-mock,可以使用yarn或npm。
yarn add -D jest-canvas-mock
然后将其添加到您的[jest.config.js
或package.json
中的jest配置部分。
setupFiles: [
'jest-canvas-mock',
'<rootDir>/config/jest/setupFiles'
]