angular - NullInjectorError:StaticInjectorError(DynamicTestModule)[ToastrService -> InjectionToken ToastConfig]:在 tslint 角度 8
问题描述
当我在 Angular 8 项目中运行单元测试时,我在 ngx-toastr 中发现了一个错误
NullInjectorError:StaticInjectorError(DynamicTestModule)[ToastrService -> InjectionToken ToastConfig]:
我在 spec.ts 文件中导入了所需的模块,并且我在 app.module.ts 中声明了 forRoot()
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MatTabsModule,
ReactiveFormsModule,
MatTooltipModule,
HttpClientTestingModule,
RouterTestingModule,
ToastrModule
],
declarations: [CommunicationComponent],
providers: [
ToastrService,
]
})
.compileComponents();
}));
解决方案
从'ngx-toastr'导入{ToastrModule};
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ToastrModule.forRoot()],
})
.compileComponents();
}));
如上所示在导入中添加 ToastrModule.forRoot() ,您的错误可能会得到解决
推荐阅读
- python-3.x - Changing order of execution in python
- c++ - 使用继承来解决库中的错误
- javascript - vuejs this.$refs 用于多个元素
- python - 延迟子查询加载 SQLAlchemy
- c++ - 有什么方法可以读取一行上包含多个整数的文本文件并保存到 Vector C++
- ros - ROS:Rviz - 发布点 - 订阅者 - 获取 x,y 坐标
- java - 我在 sleep() 时中断了方法并且没有异常
- kotlin - 返回包含特定列表类型作为参数的列表的扩展函数
- algorithm - 如何修剪这种类型的排序加权树以最大化这个特定的功能?
- react-native - 试图更新高位图表数据