升级到 Angular 10 后,我在运行库的单元测试时遇到问题。
我有两个项目库。例如 LibTest1 HeroTest2
HeroTest2 消耗 LibTest1
项目 tsconfig.json 包含
{
.......
"baseUrl": "./",
.....
"paths": {
"LibtTest1": [
"dist/LibTest1"
],
"LibTest1/*": [
"dist/LibTest1/*"
],
"HeroTest2": [
"dist/HeroTest2"
],
"HeroTest2/*": [
"dist/HeroTest2/*"
]
}
}
}
项目库 HeroTest2 tsconfig.lib.json 包含
"
{
extends": "../../tsconfig.json",
.....
}
项目库 HeroTest2 tsconfig.spec.json 包含
"
{
extends": "../../tsconfig.json",
.....
}
项目库 HeroTest2 package.json 包含
{
"name": "HeroTest2",
.....
"dependencies": {
"LibTest1": "*",
"tslib": "^2.0.0"
},
.....
}
我将 HeroTest2 中的 LibTest1 导出模块导入为
import {someModuleFromLibTest1} from 'LibTest1';
构建库并运行应用程序时没有问题。HeroTest2 识别 LibTest1 并且构建良好。
在 HeroTest2 的单元测试中,我添加了来自 LibTest1 的模块
import {someModuleFromLibTest1} from 'LibTest1';
.....
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ .... ],
imports: [...., someModuleFromLibTest1, ...]
})
.compileComponents();
}));
....
为 HeroTest2 运行单元测试时出现以下错误
Error: Unexpected value 'someModuleFromLibTest1' imported by the module 'DynamicTestModule'. Please add an @NgModule annotation.
任何帮助,将不胜感激。