【发布时间】:2021-08-09 02:18:18
【问题描述】:
我有一个私有方法
private checkProjectType(el: Project) {
switch (el.type) {
case 'Blue':
return this.handleBlueCheck(el);
case 'Red':
return this.handleRedCheck(el);
}
}
项目已定义
export interface Project {
id?: string;
cloneId?: string;
name?: string;
description?: string;
type?: string;
tips?: string;
}
我没有使用 jasmine 和 Karma coverage 的 Unit Test private 经验。请帮帮我!
【问题讨论】:
-
在我看来,你不应该直接测试私有方法。我想这个私有方法是在公共空间的某个地方使用的,所以如果你愿意,你可以通过调用 public 来测试私有方法。
-
您需要测试调用私有方法的公共方法并断言它产生的更改。
标签: angular jasmine karma-jasmine