我需要测试一个组件,但是得到了这个错误信息:NullInjectorError: R3InjectorError(DynamicTestModule)[AuthenticationService -> Router -> Router]: NullInjectorError: No provider for Router!**" 我正在测试的组件有两个依赖项,但我不知道如何在测试时使用testbed提供这两个依赖项。 gallery.component.ts
constructor( private authService:AuthenticationService, private iterableDiffers: IterableDiffers){
this.iterableDiffer = iterableDiffers.find([]).create(null);
}
gallery.component.spec.ts
describe('GalleryComponent', () => {
let component: GalleryComponent;
let fixture: ComponentFixture<GalleryComponent>
let authServiceMock: AuthenticationService
let iterableDifferMock: IterableDiffers
beforeEach(() => {
TestBed.configureTestingModule({
providers:[GalleryComponent, {provide:AuthenticationService}, {provide:IterableDiffers}]
})
fixture = TestBed.createComponent(GalleryComponent);
component = fixture.componentInstance;
authServiceMock = TestBed.inject(AuthenticationService)
})
...
如何同时提供依赖项?
我阅读了Angular文档,但没有找到解决方案,我还在SO上看到其他问题,但没有找到解决方案。
谢谢