У меня есть функция, известная как canshow () в моем файле controller.ts, как показано ниже. Пожалуйста, помогите мне, как написать функциональный тест в controller.spe c .ts
Функция в controller.ts :
canShow() {
if (!this.scheme) {
return;
}
if (this.scheme.relevant === 'No') {
this.$scope["Form_" + this.GroupIx].$setValidity("relevant", false);
return true;
}
if (this.scheme.relevant === 'Yes') {
this.$scope["Form_" + this.GroupIx].$setValidity("relevant", true);
return false;
}
return;
}
Пробовал писать тестовую функцию в controller.spe c .ts:
describe("canShow", () => {
it("should set scheme to undefined", () => {
controller = $controller("SchemeController", {$scope: $scope}, $scope);
$scope.scheme = undefined;
expect(controller.canShow()).toBeUndefined();
});
it("should return false if relevant is No", () => {
controller = $controller("SchemeController", {$scope: $scope}, $scope);
expect(controller.canShow().toBe(false);
});
it("should return true if relevant is Yes", () => {
controller = $controller("SchemeController", {$scope: $scope}, $scope);
expect(controller.canShow().toBe(true);
});
});
Первый случай - получение прошел второй и третий случай - не удалось.
Может ли кто-нибудь помочь в этом по приоритету
Заранее спасибо!