0

The Problem

rxjs map() is not included in istanbul code coverage report, despite the lines being tested. The other questions related to this cover http-testing, which this isn't about. I need to either find a way to test pipes or exclude statements inside pipe() from coverage reports.

Description

I have an Akita entity store and query for vehicles. Based on some settings a vehicle can use either frontendLocation if it exists or CurrentLocation (naming is not up to me).

vehicle.query.ts

export class VehicleQuery extends QueryEntity<VehicleState, Vehicle> {
    /** Returns an observable<number[]>, e.g. [50, 50] */
    location$ = this.selectActive().pipe(
        filterNil,
        map((v) => v.frontendLocation || v.CurrentLocation), // This is shown as not covered 
        distinctUntilChanged(_.isEqual)
    );
    // ...constructor etc.
}

In my spec file I set an active vehicle with a frontendLocation and test that the query:

  1. Gets the frontendLocation of the vehicle if it exists
  2. Gets the CurrentLocation of the vehicle if frontendLocation doesn't exist.
describe('VehicleQuery', () => {
    const vehicle = { ...otherAttributes, frontendLocation: [50, 50], CurrentLocation: [49, 49] };
    let query: VehicleQuery;
    let store: VehicleStore;
    beforeEach(() => {
        TestBed.configureTestingModule({
            providers: [VehicleQuery, VehicleStore],
        });
        query = TestBed.get(VehicleQuery);
        store = TestBed.get(VehicleStore);
        store.add(vehicle);
        store.setActive(vehicle.Id);
    });
    describe('location', () => {
        it('Returns frontendLocation of current vehicle if it exists', () => {
            query.location$.subscribe((s) => {
                expect(s).toEqual([50, 50]);
                expect(s).not.toEqual([49, 49]);
            });
        });
        it("Returns CurrentLocation of current vehicle if frontendLocation doesn't exist", () => {
            store.updateActive({ frontendLocation: null });
            query.location$.subscribe((s) => {
                expect(s).toEqual([49, 49]);
                expect(s).not.toEqual([50, 50]);
            });
        });
    });

This covers both options inside the query's location$ pipe. Both tests pass, but the map() on line 4 of the query still shows up as not covered.

micaminoff
  • 26
  • 3

0 Answers0