首页 > 解决方案 > 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];

但我不明白上述错误是什么意思?

标签: angular5karma-jasmine

解决方案


推荐阅读