【发布时间】:2018-03-14 02:53:38
【问题描述】:
我正在尝试使用 typescript 为 angular 2 中的方法编写单元测试用例。因为我有一个局部变量来决定调用哪个函数。
getData(){
let condition = route.queryParam.refer;
if(condition === 'productWithChild'){
this.LoadProductWithChildData();
} else if(condition === 'product') {
this.LoadProduct();
}else{
this.showMessage('No Data is Available');
}
}
请建议如何为此方法编写单元测试用例。
【问题讨论】:
-
我不太确定你为什么要测试这个。使用您的代码,
if()语句是唯一会被执行的语句。能否请您发布其他代码,以便我可以尝试提供更好的帮助? -
getData(){ 让条件 = route.queryParams.refer; if(condition){ // 调用方法 1 } else { // 调用方法 2 } }
-
你能用这段代码编辑你的原始帖子,以便我更好地阅读吗?谢谢! :)
-
我从 url 查询参数中得到
refer。基于此决定应该调用哪个方法
标签: angular jasmine karma-jasmine