假设我有一个类Foo为其所有派生类提供依赖注入服务,如下所示:
export class Foo {
protected fb : FormBuilder;
protected router : Router;
protected otherService : OtherService;
protected anotherService : AnotherService;
constructor(injector : Injector) {
this.fb = injector.get(FormBuilder);
this.router = injector.get(Router);
this.otherService = injector.get(OtherService);
this.anotherService = injector.get(AnotherService);
}
Run Code Online (Sandbox Code Playgroud)
它具有从它派生的类:
export class Bar extends Foo {
constructor(injector : Injector){
super(injector);
}
}
Run Code Online (Sandbox Code Playgroud)
如何正确地对父类进行单元测试,而不会遇到:
Error: Can't resolve all parameters for Foo: (?)
目前我已经(尝试了很多很多不同的东西来让它工作,但失败了:()
export function main() {
describe('Class: Foo', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
providers: [ …Run Code Online (Sandbox Code Playgroud)