我正在尝试为循环中的 if 条件编写一个测试用例,但是我没有将它作为过滤器的一部分。有什么方法可以测试循环中的 if 条件。我的测试用例根本不执行这行代码。
下面是我的控制器代码
$scope.init = function()
{
for (var i = 0; i < $scope.tempdata.length; i++) { //mapping of the status to text
if ($scope.tempdata[i].Status == 'U') {
$scope.statusText = 'text1';
}
if ($scope.tempdata[i].Status == 'A' || $scope.tempdata[i].Status == 'W') {
$scope.statusText = 'text2';
}
if ($scope.tempdata[i].Status == 'F') {
$scope.statusText = 'text3';
}
if ($scope.tempdata[i].Status == 'P') {
$scope.statusText = 'text4';
}
if ($scope.tempdata[i].Status == 'E') {
$scope.statusText = 'text5';
}
if ($scope.tempdata[i].Status == 'S') {
$scope.statusText = 'text6';
}
}
}
下面是我的测试用例
it('should set the status', function() {
scope.responseSet = true;
var mockTempData =[{'Status': 'F'}];
scope.tempdata = mockTempData
scope.init();
expect(scope.statusText).toBe(text3);
});
当我运行业力时,我的测试用例失败,Expected '' to be text3.