2016-09-15 82 views
0

我有以下代碼:

angular.module('ps.workspaces').config(['$provide', function($provide) { 
    $provide.factory('workspacesNonCompliance', ['$filter', function($filter) { 
    return { 
     NonComplianceReasons: [ 
     {name: $filter('translate')('NONCOMPLIANT.ALL'), noncompliant_properties: '' }, 
     {name: $filter('translate')('NONCOMPLIANT.JAIL_BREAK_DETECTION'), noncompliant_properties: 'jail_break_detection' }, 
     {name: $filter('translate')('NONCOMPLIANT.COMPLIANCE_ROOTED_DETECTION'), noncompliant_properties: 'compliance_rooted_detection' }, 
     {name: $filter('translate')('NONCOMPLIANT.COMPLIANCE_USB_DEBUGGING'), noncompliant_properties: 'compliance_usb_debugging'}, 
     {name: $filter('translate')('NONCOMPLIANT.POLICY_EXPIRED'), noncompliant_properties: 'policy_expired'} 
     ] 
    }; 
    }]); 
}]); 

我的模塊是:

angular.module('ps.workspaces', [ 
    'ps.workspaces.workspacesDirective', 
    'ps.workspaces.workspacesFactories' 
]); 

我的測試是:

describe('Tests for workspacesNonCompliance /', function() { 
    var workspacesNonCompliance, 
     $provider, 
     $filter; 

    // beforeEach(module('ps.workspaces')); 
    // beforeEach(module('ps.workspaces.workspacesDirective')); 
    // beforeEach(module('ps.workspaces.workspacesFactories')); 

    beforeEach(function(){ 
    angular.module('ps.workspaces', [ 
     'ps.workspaces.workspacesDirective', 
     'ps.workspaces.workspacesFactories' 
    ]); 
}); 

    describe('workspacesNonCompliance is array of noncompliance reasons /', function() { 
    beforeEach(function() { 
     inject(function ($injector) { 
     workspacesNonCompliance = $injector.get('workspacesNonCompliance'); 
     $filter = $injector.get('$filter'); 

     }); 
    }); 

    it('workspacesNonCompliance has array of noncompliance reasons', function() { 
     console.log('******* workspacesNonCompliance ', workspacesNonCompliance); 
     expect(workspacesNonCompliance.NonComplianceReasons).toContain({name: $filter('translate')('NONCOMPLIANT.ALL'), noncompliant_properties: '' }); 
    }); 

    }); 
}); 

試跑並得到錯誤信息:

錯誤:[$注射器:unpr]未知提供商:workspacesNonComplianceProvider < - workspacesNonCompliance http://errors.angularjs.org/1.3.18/ $注射器/ unpr P0 = workspacesNonComplianceProvider%20%3 C-%20workspacesNonCompliance 在/用戶/ joannepham/GIT中/ PWS /控制檯的UI/bower_components/angular/angular.js:63:12 at /Users/joannepham/git/pws/console-ui/bower_components/angular/angular.js:4031:19

找不到需要修復的內容這個案例。請幫忙

回答

0

不知道ps.workspaces.workspacesDirectiveps.workspaces.workspacesFactories有什麼。但這裏的主要問題是,workspacesNonCompliance沒有正確注入。這就是爲什麼它會以undefined的方式出現,從而導致錯誤。

您的測試文件應該是這樣的:

describe('Tests for workspacesNonCompliance /', function() { 
 
    var workspacesNonCompliance, $provider, $filter; 
 

 
    beforeEach(function() { 
 
    module('ps.workspaces'); 
 
    }); 
 

 
    beforeEach(inject(function(_workspacesNonCompliance_) { 
 
    workspacesNonCompliance = _workspacesNonCompliance_; 
 
    })); 
 

 
    describe('workspacesNonCompliance', function() { 
 
    it('should have workspacesNonCompliance as defined', function() { 
 
     expect(workspacesNonCompliance).toBeDefined(); 
 
    }); 
 
    }); 
 
});

希望這有助於。

相關問題