在单元测试中出现笑话

问题描述 投票:0回答:1

当我运行单元测试时,我发现以下错误:

Error: Not implemented: HTMLCanvasElement.prototype.getContext 
(without installing the canvas npm package)
typescript visual-studio-code jestjs html5-canvas jsdom
1个回答
0
投票

要解决此问题,首先必须安装jest-canvas-mock,可以使用yarn或npm。

yarn add -D jest-canvas-mock

然后将其添加到您的[jest.config.jspackage.json中的jest配置部分。

setupFiles: [
    'jest-canvas-mock',
    '<rootDir>/config/jest/setupFiles'
  ]
© www.soinside.com 2019 - 2024. All rights reserved.