e2e检验中的角度依赖注入

问题描述 投票:0回答:1

我在测试中与DI斗争。

案件很简单。我有一项服务,在测试时我只想注入不同的服务。

我做了:

beforeEach(() => {
  TestBed.overrideProvider( AuthService, {useValue: MockAuthService(??)});
  TestBed.configureTestingModule({
    declarations: [ LoginComponent ],
    providers: [ AuthService ]
  }).compileComponents();
  page = new AppPage();
}

MockAuthService继承自真正的AuthService。在那里我在构造函数中注入了另一个服务。我不知道该怎么做。

还有另外一种方法吗?怎么了?

很多,最好的问候,尼古拉斯

angular dependency-injection e2e-testing
1个回答
0
投票
beforeEach(() => {
    TestBed.configureTestingModule({
        declarations: [ LoginComponent ],
        providers: [ 
            {provide: AuthService, useClass: MockAuthService}
        ]
    }).compileComponents();
    page = new AppPage();
}
© www.soinside.com 2019 - 2024. All rights reserved.