angular5 - TypeError:在angular5中进行单元测试时无法读取未定义问题的属性“拆分”
问题描述
我正在尝试在 angular5 中进行单元测试,并解决键入命令“ng test”时显示的大多数测试错误。但我遇到了以下错误。
TypeError: Cannot read property 'split' of undefined
我在我的组件中使用 javascript string split() 方法来拆分字符串。
this.currentUrlPath = this.router.url;
this.currentUrlPathAsArray = this.currentUrlPath.split('/');
this.currentUrlPathAsArray.shift();
this.currentOfferKey = this.currentUrlPathAsArray[0].split('offer-')[1].split('-program')[0];
但我不明白上述错误是什么意思?
解决方案
推荐阅读
- powerbi - 如何为 power bi visual(仪表板页面)/报告表上的特定列标题提供通用标题
- java - 无法拒绝符号“位置”
- python - 有没有办法将 .pkl 文件转换为 .pb 或 .tflite 文件以在 android 中使用?
- python - BeautifulSoup:查找与一个标签匹配的任何标签,或按属性匹配另一个标签
- c++ - C++ successfully copying dynamically allocated obj without copy ctor?
- python - 无法从“pyproj”导入名称“CRS”以使用 osmnx 库
- json - 将 JsonArray 值分配给匹配案例类的变量
- c++ - 如何使用 Visual Studio 2008 将字符串映射到函数?
- python - Drive API v3 - Getting all files inside a particular folder
- docker - 运行 Docker 映像的问题