angular - 无法读取未定义的属性“_lastPathIndex”
问题描述
我在我的组件规范中模拟激活路由,如下所示:
class ActvatedRouterMock {
public paramMap = of(convertToParamMap({
level: 'customer',
id: '12345',
}));
}
在提供者部分也添加这个类。
但是当我运行我的测试用例时,我收到错误无法读取_lastPathIndex
未定义的属性
版本:Angular8 任何人都可以帮助我解决这个问题吗?
解决方案
可能在您的生产代码中,您有类似的内容:
this.router.navigate(['../'], {
relativeTo: this.route
});
然后你需要为snapshot
你激活的路由提供一个属性。
例子:
class ActvatedRouterMock {
public paramMap = of(convertToParamMap({
level: 'customer',
id: '12345',
}));
public snapshot = new ActivatedRouteSnapshot();
}
推荐阅读
- java - 我在运行 react-native run-android 时遇到了这个问题
- android - 以编程方式在 Android 中获取电话号码
- javascript - 在不覆盖对象的情况下更改 b 中的对象属性的最简单方法是什么?
- javascript - 如何在标签内启用按钮或 div 悬停检测?
- angularjs - 使用 require 节点模块从文件夹中读取 json 文件
- node.js - 护照注销()错误:模型“somemodel(不是用户模型)”的路径“_id”处的值“logout”转换为 ObjectId 失败
- java - Hadoop 节点未激活
- ruby - Typhoeus Ruby 删除请求中的有效负载
- android - 将 androidPlugin 更新到 3.2.1 后无法解析自定义 buildType 的依赖关系
- excel - 扑克经销商逻辑