我在现有函数中添加了一个小修改。我们的质量检查已将其识别为新代码,因此我需要用单元测试覆盖新的 4 行 - 记住,一开始就没有单元测试,而且我添加的函数非常大!
我尝试了多种方法来尝试模拟服务、变量、间谍活动等……但总是出错。我对茉莉花很陌生,所以很挣扎。我需要做的就是进行任何类型的检查以覆盖真值/假值。
组件.ts 文件
hasDescription() {
return this.isBrilliant() || this.isCool();
}
isBrilliant() {
return this.service.Type.description == 'Brilliant';
}
isCool() {
return this.service.Type.description == 'Cool';
}
onExportToExcel(): void {
var r = [];
// added the below if/else - any check on this will be suffice.
if (this.hasDescription()) {
if (!this.isBrilliant()) {
r.push('This is Cool');
} else {
r.push('This is Brilliant');
}
if (!this.isBrilliant()) {
r.push('More Cool content');
}
}
}
我尝试将isBrilliant() 设置为模拟值true,并期望该值是真实的expect(component.isBrilliant()).toBeTruthy();
我尝试通过以下方式在规范文件中设置它:
const isBrilliant = true;
component.isBrilliant = isBrilliant;
然而我在这里得到的错误是Type 'true' is not assignable to type '() => boolean'.
如果任何经验丰富的 jasmine 开发人员可以向我展示一种快速方法来覆盖这个简单的声明,我将不胜感激。谢谢
跃然一笑
相关分类