angular - ● 测试套件无法运行 Jest 遇到意外的令牌导出 { BsModalRef }
问题描述
使用 BS-MODAL 等 js 库时无法运行测试用例。细节:
/home/test-app/node_modules/ngx-bootstrap/modal/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export { BsModalRef } from './bs-modal-ref.service';
解决方案
我将ngx-bootstrap添加到transformIgnorePatterns工作正常。
"transformIgnorePatterns": [
"node_modules/(?!ngx-bootstrap)"
]
如果在添加 ngx-bootstrap 后又出现一个错误
Error: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package)
- 安装
jest-canvas-mock
- 在里面添加配置
jest config:setupFiles: ['<rootDir>/src/setupJest.ts', 'jest-canvas-mock']
最后在你的角度package.json文件中开玩笑链接这个
"jest": {
.........,
..........
"setupFilesAfterEnv": [
"<rootDir>/src/setupJest.ts",
"jest-canvas-mock"
],
"transformIgnorePatterns": [
"node_modules/(?!ngx-bootstrap)"
],
............,
............
}
参考链接https://github.com/hustcc/jest-canvas-mock/issues/2#issuecomment-500307391
我遵循相同的步骤并为我工作。
推荐阅读
- html - @font-face .ttf 导致加载时间变慢
- javascript - Lightbox2 不会阻止浏览器跟随链接
- c# - 在邮递员上不断收到 < 和 > XML 响应
- python - 通过在列中的两个值之间插值并分别计算中位数来填充表中的 nan 值
- python - 如何放置超过 1 个输入框,当我单击验证时,它会在 tkinter 上一次性创建变量?
- css - 使用无法居中的 Tailwind flex 项目
- javascript - 如何检测以前在浏览器中不可见的元素的可见性?
- prestashop - Prestashop:当订单状态更改为“已发货”时获取订单详细信息
- tensorflow - UnimplementedError:文件系统方案“[本地]”未实现(文件:“/content/drive/MyDrive/foop/train/beet_salad/2056837.jpg”)
- javascript - 是的架构。如何仅验证 YupSchema 中数组的第一个元素