我在测试中与DI斗争。
案件很简单。我有一项服务,在测试时我只想注入不同的服务。
我做了:
beforeEach(() => {
TestBed.overrideProvider( AuthService, {useValue: MockAuthService(??)});
TestBed.configureTestingModule({
declarations: [ LoginComponent ],
providers: [ AuthService ]
}).compileComponents();
page = new AppPage();
}
MockAuthService继承自真正的AuthService。在那里我在构造函数中注入了另一个服务。我不知道该怎么做。
还有另外一种方法吗?怎么了?
很多,最好的问候,尼古拉斯
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ LoginComponent ],
providers: [
{provide: AuthService, useClass: MockAuthService}
]
}).compileComponents();
page = new AppPage();
}