[英]Testing Lodash sortBy function argument using Jasmine
我的项目中有一个控制器,如下所示:
define(function (require) {
'use strict';
function AllOrgsController($rootScope, $uibModalInstance) {
var vm = this;
var clonedOrgs = _.cloneDeep($rootScope.userData.org);
vm.modelContainer = _.sortBy(clonedOrgs, function (org) {
return org.organizationName.toLowerCase();
});
vm.openFacilityModal = function () {
$uibModalInstance.close();
};
vm.saveOrgsModal = function () {
$uibModalInstance.close({ $value: vm.currentFacility });
};
vm.cancelOrgsModal = function () {
$uibModalInstance.dismiss();
};
}
AllOrgsController.$inject = ['$rootScope', '$uibModalInstance'];
return AllOrgsController;
});
但是伊斯坦布尔并未涵盖在Lodash的_.sortBy
方法中使用的匿名函数。 由于我是单元测试的新手,所以我不知道为什么-有人知道吗?
_.sortBy
应该为您提供的clonedOrgs
参数的每个元素调用传递的函数。 由于Istanbul检测到传递的函数从未运行过,因此这必须意味着您的测试中clonedOrgs
始终为空(或不是有效数组)。 因此,您可以通过编写一个其中$rootScope.userData.org
数组包含元素的测试来确保该方法被覆盖。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.