mardi 28 janvier 2020

Angular testing: Method returning an observable is successfully tested, but test coverage still marks it as noncovered statement

I want to test this method:

public getAll(): Observable<Array<Todo>> {
    return this.$http.get<Array<Todo>>('http://5def6a2502b2d90014e1b38a.mockapi.io/api/v1/todos/');
}

I've written a test for this method:

it('should return array of todos', (done: DoneFn) => {
    const mockedValue = [new Todo('Test')];
    spyOn(service, 'getAll').and.returnValue(of(mockedValue));
    service.getAll().subscribe((value) => {
        expect(value).toBe(mockedValue);
        done();
    });
});

When i run ng test, this test is marked as successful, but code-coverage still marks it like an uncovered test:

enter image description here

Why? And how I can cover it?

Aucun commentaire:

Enregistrer un commentaire