angular - 模块“DynamicTestModule”导入的意外值“ModalModule”
问题描述
我正在尝试测试MyComponent
哪个使用 ngx-bootstrap 的模态指令(如https://valor-software.com/ngx-bootstrap/#/modals#directive-section所示)。该组件本身可以完美运行,但是在尝试对其进行测试时,出现此错误:
Unhandled Promise rejection: Unexpected value 'ModalModule' imported by the module 'DynamicTestModule'. Please add an @NgModule annotation.
这就是我的 TestBed 的样子:
TestBed.configureTestingModule({
imports: [
HttpClientTestingModule,
RouterTestingModule.withRoutes([]),
ModalModule.forRoot()
],
declarations: [MyComponent],
providers: [],
schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(MyComponent);
component = fixture.componentInstance;
});
这就是模态的设置方式MyComponent
:
export class MyComponent implements {
@ViewChild('confirmDeleteModal')
confirmDeleteView: ModalDirective;
constructor() {} // empty constructor just to illustrate the fact that there are no other dependencies
作为参考,这是我的模板的相关部分:
<div bsModal #confirmDeleteModal="bs-modal" class="modal fade" role="dialog"> ... </div>
这是我已经尝试过的:
ModalModule.forRoot()
从列表中删除imports
,然后给我这个错误:
Unhandled Promise rejection: Export of name 'bs-modal' not found!
添加ModalDirective
到列表中declarations
:
Unhandled Promise rejection: R3InjectorError(DynamicTestModule)[ComponentLoaderFactory -> ComponentLoaderFactory]:
NullInjectorError: No provider for ComponentLoaderFactory!
我究竟做错了什么?
解决方案
您还需要添加BsModalService
到您的提供者数组。
推荐阅读
- java - ZipEntry脚本压缩一个目录,15个文件中有14个是空白的
- sql - 检查列级别的不同值
- ios - 显示来自 iOS 广播扩展的自定义错误消息
- kendo-ui - TabStrip 中的 Kendo UI 模板语法
- python - 比较字典列表中的键
- c# - 配置文件不是格式良好的网站中的 XML 错误,为什么?
- android-studio-3.0 - 如何为从android中的数据库中获取的每条记录制作单选按钮组
- c# - 请有人可以帮助它只显示作业,cal
- python - 如何修复此 Python 登录系统代码?
- python - 求解带有 f (x) 数值但没有分析表达式的 ode y'=f (x)