В настоящее время я пытаюсь смоделировать / заглушить / шпионить за службой, чтобы я мог установить возвращаемое значение на другое значение для ряда тестов.
например.
mockService.getCountOfItems.and.returnValue.(of(1));
// some expectations
mockService.getCountOfItems.and.returnValue.(of(0));
// some expectations
Однако это почему-то кажется невозможным.Я что-то упускаю здесь действительно очевидное?
код:
const mockService = {
getCountOfItems: () => of(0)
};
describe('Component', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [Component],
imports: [...],
providers: [
{ provide: Service, useValue: mockService}
]
}).compileComponents();
}));
it('should enable btn when items available', async(() => {
const btn = fixture.debugElement.query(By.css('#myBtn')).nativeElement;
mockService.getCountOfItems.and.returnValue(of(1));
expect(myBtn.disabled).toBeFalsy();
}));
Спасибо