假设我在同一个描述块中有两个测试用例,需要使用相同的服务,但每个测试用例都必须提供不同的服务存根?下面的示例将按预期为两个测试用例提供 serviceStub1,但我需要找到一种方法为第二个用例提供 serviceStub2。我已经花了很多时间在这上面,但到目前为止我迷路了。任何帮助将不胜感激,谢谢。
describe('Component: ComponentUnderTest', () => {
const serviceStub1 = {
method: () => value1;
};
const serviceStub2 = {
method: () => value2;
};
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ComponentUnderTest],
providers: [
{provide: Service, useValue: serviceStub1},
]
});
fixture = TestBed.createComponent(ComponentUnderTest);
});
//should be tested with serviceStub1
it("should do something when provider method returns value 1");
//should be tested with serviceStub2
it("should do something when provider method returns value 2");
});