问题
大家好!第一次在这里提问,希望得到帮助。我目前正在开发一个 Electron+Angular 应用程序,我终于准备测试所有服务和组件。在尝试启动使用 WebStorm 创建的示例规范以及组件和服务时,我面临当前错误:
NullInjectorError: StaticInjectorError(DynamicTestModule)[InjectionToken ToastConfig]:
StaticInjectorError(Platform: core)[InjectionToken ToastConfig]:
NullInjectorError: No provider for InjectionToken ToastConfig!
Run Code Online (Sandbox Code Playgroud)
这是我试图运行的简单测试文件
import {TestBed} from '@angular/core/testing';
import {CognitoService} from './cognito.service';
import {ToastrModule, ToastrService} from 'ngx-toastr';
describe('CognitoService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [ToastrModule.forRoot()],
providers: [
CognitoService,
{provide: ToastrService, useClass: ToastrService}
]
}).compileComponents();
});
it('should be created', () => {
const service: CognitoService = TestBed.get(CognitoService);
expect(service).toBeTruthy();
});
});
Run Code Online (Sandbox Code Playgroud)
这是我从运行测试中获得的堆栈跟踪
NullInjectorError: StaticInjectorError(DynamicTestModule)[InjectionToken ToastConfig]:
StaticInjectorError(Platform: core)[InjectionToken ToastConfig]:
NullInjectorError: No provider for InjectionToken ToastConfig!
error …Run Code Online (Sandbox Code Playgroud)