JS单元测试使用karma和Jesmine

时间:2016-01-28 05:42:18

标签: 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) {

    }
};

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 ,如下所示

else if(plugin == 'CompanyInfo'){
            return {
                'company_name': 'company_name',
                'company_id': 'company_id'
            };
        }

我在考试中错过了什么。预感谢并得到任何帮助我的人的建议。

0 个答案:

没有答案