2016-07-11 14 views
1

私はJasmineを使って書いている角度サービスのテスト駆動開発をしようとしています。しかし、私は最初の障害に遭遇したようで、解決するために$リソースの依存関係を得ることはできません。テストのためのAngularサービスへの依存関係の注入

私が手にエラーが 不明プロバイダです:$のResourceProvider < - $リソース< - lookupService

次のように私のコードがある

モジュール:

(function() { 
'use strict'; 

angular 
    .module('common', ['ngSanitize', 'ngAnimate']); 
})(); 

サービス:

(function() { 
'use strict'; 

angular 
    .module('common') 
    .service('lookupService', lookupService); 

lookupService.$inject = ['$resource', 'api']; 

function lookupService($resource, api) { 
    return { 
     getLookup: getLookup 
    }; 

    function getLookup() { 
     return "something"; 
    } 
} 

})(); 

テスト:

describe('Service tests', 
function() { 

    var lookupService, mockApi, $httpBackend; 

    //mocks 
    beforeEach(function() { 
     mockApi = { getUri: jasmine.createSpy() }; 

     angular.mock.module('common', 
      function ($provide) { 
       $provide.value('api', mockApi); 
      }); 
    }); 


    //injects 
    beforeEach(function() { 
     inject(function ($injector) { 
      $httpBackend = $injector.get('$httpBackend'); 
      lookupService = $injector.get('lookupService'); 
     }); 
    }); 



    //tests 
    it('should be able to return something', 
     inject(function() { 
      expect(lookupService.getLookup()).toEqual("something"); 
     })); 

});//Service tests 

angle-resource.jsファイルは、自分のランナーファイルに含まれています。どこが間違っているのか分かりません。何か助けていただければ幸いです。

おかげ

+0

あなたはカルマを使用していますか? karma.conf.jsを確認して、jsファイルがすべて含まれているのを確認できますか? – Srijith

+0

私は実際にスタンドアロンのジャスミンを使ってそれらを実行しています。モジュール、サービス、テスト、すべてのanguarjsファイルはSpecRunnerファイルに含まれています。 –

答えて

1

ngResourceは依存関係である必要があります。

(function() { 
'use strict'; 

angular 
    .module('common', ['ngSanitize', 'ngAnimate', 'ngResource']); 
})(); 
+0

ああ!もちろん! –

関連する問題