Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 使用karma和Jesmine的JS单元测试_Angularjs_Unit Testing_Karma Jasmine - Fatal编程技术网

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意味着该语句永远不会执行。我如何解决它?