问题
rxjsmap()
未包含在伊斯坦布尔代码覆盖率报告中,尽管正在测试这些行。与此相关的其他问题包括 http-testing,这与此无关。我需要找到一种方法来测试管道或pipe()
从覆盖率报告中排除语句。
描述
我有一个秋田实体商店和车辆查询。根据某些设置,车辆可以使用(frontendLocation
如果存在)或CurrentLocation
(命名不由我决定)。
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.
}
在我的规范文件中,我设置了一个带有 frontendLocation 的活动车辆并测试查询:
- 获取车辆的前端位置(如果存在)
- 如果 frontendLocation 不存在,则获取车辆的 CurrentLocation。
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]);
});
});
});
这涵盖了查询location$
管道内的两个选项。两个测试都通过了,但map()
查询的第 4 行仍然显示为未覆盖。