angular - TypeError:无法读取未定义的属性“get”(Angular getter)
问题描述
运行测试规范时在 ts 中出现错误。角度获取函数()。我曾尝试在该物业上创建一个间谍,但没有成功..
规格:
const spyC = spyOnProperty(component, 'contractId').and.returnValue(new
FormGroup({}));
或者
const spyC = spyOnProperty(component, 'contractId').and.callThrough();
expect(spyC).toHaveBeenCalled();
TS:
get contractId() {
return this.formService.queryParamSnapshot.get('contractId');
}
解决方案
似乎必须与提供者打交道:
{provide: AuthService, useClass: MockAuthService}
const fakeActivatedRoute = {
snapshot: {data: {}}
} as ActivatedRoute;
推荐阅读
- unity3d - 已删除的资产仍显示在构建日志中?
- javascript - 通过 importrange 导入数据时将数据行存档到另一个选项卡(Google 表格)
- c++ - C++11 Cereal 序列化 - 版本控制
- r - 自举到 Fisher 测试
- node.js - 如何清理 NodeJS 中的数据(删除括号和引号)?
- java - 使用 java 工具的 CQL 查询 WITHIN
- azure - WVD 展望提示未经许可/非商业产品
- css - Asp.Net MVC 项目中的 css 样式
- laravel - 带有ValidationException的Laravel“抛出”返回500而不是422?
- kotlin - 列表中的 Kotlin 过滤器列表