获得错误无法在角度单元测试中设置未定义的属性
当我编写单元测试案例以进行下拉列表时,我会遇到错误 typeError:无法设置未定义的属性(设置“转码”) .spec.ts
it("should update the action selecting a value from category drop down", () => {
component.actionCodesLookupData.ReferralCodes =[
{
Name: "some data",
Id: 3,
ActionStatus: 126
}
]
component.setActionCodesList("Referral");
expect(component.actionCodesList).toBe(component.actionCodesLookupData.ReferralCodes);
});
.component.ts
public setActionCodesList(actionType: any):void{
this.actionCodesList = [];
switch(actionType){
case ActionRecordConstant.memberContact:
this.actionCodesList = this.actionCodesLookupData.MemberContactCodes;
break;
case ActionRecordConstant.referral:
this.actionCodesList= this.actionCodesLookupData.ReferralCodes;
break;
//some code
在代码中它没有显示错误,但测试未能显示错误为:
typeError:无法设置未定义的属性(设置“转介码”)
任何人都可以帮助我
while I am writing the unit test case for dropdown I am getting the error as
TypeError: Cannot set properties of undefined (setting 'ReferralCodes')
.spec.ts
it("should update the action selecting a value from category drop down", () => {
component.actionCodesLookupData.ReferralCodes =[
{
Name: "some data",
Id: 3,
ActionStatus: 126
}
]
component.setActionCodesList("Referral");
expect(component.actionCodesList).toBe(component.actionCodesLookupData.ReferralCodes);
});
.component.ts
public setActionCodesList(actionType: any):void{
this.actionCodesList = [];
switch(actionType){
case ActionRecordConstant.memberContact:
this.actionCodesList = this.actionCodesLookupData.MemberContactCodes;
break;
case ActionRecordConstant.referral:
this.actionCodesList= this.actionCodesLookupData.ReferralCodes;
break;
//some code
In code it is not showing the errors but test is failing showing the error as:
TypeError: Cannot set properties of undefined (setting 'ReferralCodes')
can anyone help me on this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的问题是
ActionCodesLookupData
在设置它时是不确定的。尝试将其设置为空对象。
I think your issue is that
actionCodesLookupData
is undefined when you set it.Try setting it to an empty object first.