gpt4 book ai didi

angular - NullInjectorError : StaticInjectorError(DynamicTestModule)[ToastrService -> InjectionToken ToastConfig]: in tslint angular 8

转载 作者:行者123 更新时间:2023-12-03 16:43:56 26 4
gpt4 key购买 nike

当我在 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() ,您的错误可能会得到解决

关于angular - NullInjectorError : StaticInjectorError(DynamicTestModule)[ToastrService -> InjectionToken ToastConfig]: in tslint angular 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59190786/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com