2
我似乎無法在角2測試牀上註冊多個提供商(服務)。我只想給測試平臺提供多種服務。這裏是我目前測試套件的一個例子。多個提供商Angular 2測試牀
export function main() {
describe('Create Applications Component test suite:',() => {
let fixtureComponent:any, nativeComponentElement:any;
beforeEach(() => {
return TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
FormsModule
],
declarations: [CreateApplicationComponent]
}).overrideComponent(CreateApplicationComponent, {
set: {
providers: [
{
provide: injector,
useClass: MockCreateApplicationService
}
]
}
})
.compileComponents().then(() => {
fixtureComponent = TestBed.createComponent(CreateApplicationComponent);
nativeComponentElement = fixtureComponent.nativeElement;
return fixtureComponent;
});
});
it('component should work without errors',() => {
expect(true).toBe(true);
});
});
}
我需要去將是這樣的:
.overrideComponent(CreateApplicationComponent, {
set: {
providers: [
{
provide: injector,
useClass: MockCreateApplicationService
},
{
provide: providerB,
useClass: SecondProvider
}
]
}
})
'我需要去將是這樣的:'什麼似乎是它的問題? –
當我添加第二個提供程序時,出現錯誤,提示「沒有提供程序的表單構建器」,因此我只是將該表單構建器添加爲overrideComponent方法中的其他提供程序,並且一切正常。謝謝你的慰問! –