En mi caso me estaba fallando la prueba “should call to getValue from ValueService” porque no había eliminado o comentado la constante interna de la prueba unitaria “const valueServiceSpy” y me generaba el siguiente error: “Error: Expected undefined to be ‘fake value’”. Al comentar la constante constante tomo el valor del valueServiceSpy que se encuentra en el scope global y no la del scope de la prueba unitaria y ahí si pasa sin problema.
it('should call getValue from spy of ValueService', () => {
// const valueServiceSpy = jasmine.createSpyObj('ValueService', ['getValue']);
valueServiceSpy.getValue.and.returnValue('fake value');
// const masterService = new MasterService(valueServiceSpy);
expect(service.getValue()).toBe('fake value');
expect(valueServiceSpy.getValue).toHaveBeenCalled();
expect(valueServiceSpy.getValue).toHaveBeenCalledTimes(1);
});
¿Quieres ver más aportes, preguntas y respuestas de la comunidad? Crea una cuenta o inicia sesión.