问题描述
问题
rxjs map()
未包含在伊斯坦布尔代码覆盖率报告中,尽管这些行正在测试中。与此相关的其他问题涵盖了 http 测试,这与本文无关。我需要找到一种方法来测试管道或从覆盖率报告中排除 pipe()
内的语句。
说明
我有一家 Akita 实体店,可以查询车辆。根据某些设置,车辆可以使用 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 的活动车辆并测试查询:
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$
管道内的两个选项。两个测试都通过了,但查询第 4 行的 map()
仍然显示为未覆盖。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)