angular - 如何修复玩笑测试 TypeError:无法设置只有 getter 的 [object Object] 的属性 selectStoreEntity$?
问题描述
如何开玩笑地测试这个只读的可观察变量?
我尝试按照本文的指示进行操作-> https://medium.com/angular-in-depth/how-to-test-observables-a00038c7faad
运行时出现此错误:
Cannot set property selectStoreEntity$ of [object Object] which has only a getter
语音-uc.service.spec.ts
// whether or not the account has uc-voice
readonly hasVoiceUc$ = this.inventory$.pipe(
map(inventory => inventory?.data?.data?.length > 0)
);
语音-uc.service.spec.ts
it('should call hasVoiceUc$', async () => {
// Testing using marbles (see https://medium.com/angular-in-depth/how-to-test-observables-a00038c7faad)
const scheduler = new TestScheduler((actual, expected) => {
expect(actual).toEqual(expected);
});
scheduler.run(({ cold, expectObservable }) => {
const values = {
a: null,
b: {
data: {},
},
c: {
data: {
data: [],
},
},
d: {
data: {
data: ['value'],
},
},
};
const source$ = cold('abcd|', values);
const expectedMarble = 'abcd|';
const expectedValues = { a: false, b: false, c: false, d: true };
(selectStoreEntity$ as any) = () => source$;
service = new VoiceUcService({} as any, loggerService);
const result$ = service.hasVoiceUc$;
expectObservable(result$).toBe(expectedMarble, expectedValues);
});
});
错误:TypeError:无法设置只有 getter 的 [object Object] 的属性 selectStoreEntity$
● VoiceUcService › should call hasVoiceUc$
TypeError: Cannot set property selectStoreEntity$ of [object Object] which has only a getter
99 | const expectedValues = { a: false, b: false, c: false, d: true };
100 |
> 101 | (selectStoreEntity$ as any) = () => source$;
| ^
102 |
103 | service = new VoiceUcService({} as any, loggerService, {} as any);
104 |
解决方案
推荐阅读
- php - PDO DELETE 没有删除所有行
- php - 坚持多对一实体的原则
- r - 如何将我的时区设置为太平洋标准时间?
- java - Selenium/Java - 无法找到带有索引的选项
- android - 自定义键盘布局不适合屏幕
- php - 如何在数据库中插入一个 csv 文件但没有逗号 - PHP
- java - 该应用程序只能管理推送通知
- python - python交换列表中的项目
- applescript - 如何在将文件分类到文件夹的 Apple 脚本上显示进度?
- postgresql - 无法在 :UNIX(端口 5432)连接到 pgsql:CL-POSTGRES::USER 的值为 NIL,它不是 STRING 类型