Angularjs 使用karma和Jesmine的JS单元测试
我已经编写了如下的单元测试Angularjs 使用karma和Jesmine的JS单元测试,angularjs,unit-testing,karma-jasmine,Angularjs,Unit Testing,Karma Jasmine,我已经编写了如下的单元测试 describe('modals', function() { beforeEach(module('DetailsApp')); var controller, rootScope, templateCache, compile, http, httpBackend; var uibModalInstance = { dismiss: function(message) { }, close: function(message) {
describe('modals', function() {
beforeEach(module('DetailsApp'));
var controller, rootScope, templateCache, compile, http, httpBackend;
var uibModalInstance = {
dismiss: function(message) {
},
close: function(message) {
}
};
var plugins = {
get: function(plugin) {
if(plugin == 'Workorder'){
return {
'workorder_id': 'workorder_id'
};
} else if(plugin == 'CompanyInfo'){
return {
'company_name': 'company_name',
'company_id': 'company_id'
};
}
}
};
beforeEach(module(function($provide) {
$provide.value('$uibModalInstance', uibModalInstance);
$provide.value('plugins', plugins);
}));
beforeEach(inject(function($controller, $templateCache, $compile, $rootScope, $http, $httpBackend) {
controller = $controller;
templateCache = $templateCache;
compile = $compile;
rootScope = $rootScope;
http = $http;
httpBackend = $httpBackend;
}));
describe('When modal functions are called', function() {
it('they should be called correctly', function() {
var $scope = {};
var companyRatingHistory = controller('companyRatingHistory', { $scope: $scope });
spyOn(uibModalInstance, 'dismiss');
spyOn(uibModalInstance, 'close');
$scope.cancel();
expect(uibModalInstance.dismiss).toHaveBeenCalledWith('cancel');
$scope.close('close');
expect(uibModalInstance.close).toHaveBeenCalledWith('close');
});
}); });
发现我的代码覆盖率显示了一个E-in-plugins-else块,如下所示
else if(plugin == 'CompanyInfo'){
return {
'company_name': 'company_name',
'company_id': 'company_id'
};
}
我在考试中错过了什么。提前表示感谢,并从任何帮助我的人那里得到任何建议。是否有任何错误消息?没有,但代码覆盖率显示E意味着该语句永远不会执行。我如何解决它呢?是否有任何错误消息?没有,但代码覆盖率显示E意味着该语句永远不会执行。我如何解决它?