DEV Community

loading...

Help with jasmine Promise then testing

tamburusdanilo profile image tamburusdanilo ・1 min read

Good evening Angular developers, particularly those involved with jasmine unit testing...
I have a hard time when it comes to more complex testing scenarios, I would like a little help from anyone who might help...

I am trying increase the code cover in my unit tests, but whe it comes to the code inside the "then" and "catch" block of my promises, I simply cannot coverage of my application, as shown in the print.

Within my spec file, I tried the following:

it('should return app values', fakeAsync (async () => {
const mockValues = {test: 123};

const mockSubject = new Subject<any>(); // create subject of your object type

const energiaServiceStub: EnergiaService = TestBed.inject(EnergiaService);

spyOn(energiaServiceStub, 'get').and.returnValue(mockSubject.asObservable());
await service.getAgenteInformacoesCadastrais(consultaContratoRequestMock);
mockSubject.next(mockValues);
mockSubject.complete();
tick();
expect(component.historic).toBeDefined();
Enter fullscreen mode Exit fullscreen mode

Thanks in advance folks! <3

Discussion (0)

pic
Editor guide