[英]Karma in angular doesn't import pixelmatch
I use pixelmatch to test canvas elements. 我使用pixelmatch测试画布元素。 While importing pixelmatch in a component file works fine, karma won't import it in a spec file.
虽然在组件文件中导入pixelmatch效果很好,但业力不会将其导入到规格文件中。
To reproduce the error: 重现该错误:
ng new someproject
cd someproject
npm install pixelmatch @types/pixelmatch
Change 更改
export = Pixelmatch
to 至
export default Pixelmatch
in 'node_modules/@types/pixelmatch/index.d.ts' 在'node_modules/@types/pixelmatch/index.d.ts'中
Since I'm still new to typescript I can't explain why it is needed but without it importing Pixelmatch is not working at all. 由于我对打字稿还不熟悉,所以我无法解释为什么需要它,但是如果没有导入,Pixelmatch根本无法工作。 Perhaps this is causing problems to karma.
也许这给业力造成了问题。
I also install karma-firefox-launcher and change karma.conf.js to run tests in firefox. 我还安装了karma-firefox-launcher并更改了karma.conf.js以在firefox中运行测试。
Now 现在
import Pixelmatch from 'pixelmatch'
in app.component.ts works fine, but the same import in app.component.spec.ts doesn't . 在app.component.ts中可以正常工作,但在app.component.spec.ts中不能相同导入。
expect(Pixelmatch).not.toBe(undefined)
is not passing. 没有过去。
I'd be grateful for some hints. 我会感谢一些提示。
Try 尝试
import Pixelmatch = require('pixelmatch')
For my NodeJS aplication with CommonJS syntax, it works like a charm! 对于我的使用CommonJS语法的NodeJS应用程序,它就像一个魅力!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.