问题描述
如果我从相对路径或 node_modules 导入,我可以成功地对使用 import
命令的组件运行 jest 测试。所以,这适用于 my.component.spec.ts:
import {MyComponent} from './my.component';
import {createComponentFactory,spectator} from '@ngneat/spectator/jest';
在我的组件模板中,我想使用一些共享管道,这些管道是项目中另一个库的一部分。理想情况下,它看起来像这样:
import {SharedPipesModule} from '@my-project/shared/pipes';
然而,这失败了:
无法从 ... 中找到模块“@my-project/shared/pipes”
我已经尝试在 tsconfig.spec.json 中使用它,但没有任何区别。
"paths": {
"@my-project/shared/pipes": ["libs/shared/pipes/src/index.ts"]
}
我使用的是 Jest v26 和 Angular 10。 如何让测试成功导入我需要的模块?
在我的 package.json 中,我有:
"@babel/preset-env": "^7.12.1","@types/jest": "^26.0.0","babel-jest": "^26.0.0","jest": "^26.0.0","jest-marbles": "^2.0.0","jest-preset-angular": "^8.0.0","ts-jest": "^26.0.0",
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)