私は、yeoman で生成した angularjs アプリケーションを持っています。karma.conf.js には、test/mock/**/*.js への参照があります。このフォルダをどのように使用するかを見つけるのに苦労しています。現在、私は単純なサービスを持っています:
'use strict';
angular.module('tvcalApp')
.factory('Series', function ($resource) {
return $resource('/search/:search');
});
そしてテスト
'use strict';
var $httpBackend;
describe('Service: Series', function () {
// load the service's module
beforeEach(module('tvcalApp'));
// instantiate service
var Series;
beforeEach(inject(function (_Series_) {
Series = _Series_;
}));
beforeEach(inject(function ($injector) {
var url_get = '/search/The%20Simpsons';
var response_get = [{"seriesid": "71663"}];
$httpBackend = $injector.get('$httpBackend');
$httpBackend.whenGET(url_get).respond(response_get);
}));
it('should return a list if search for The Simpsons', function () {
var res = Series.query({search: 'The Simpsons'});
$httpBackend.flush();
expect(res[0].seriesid === 71663);
});
});
これは機能しています。しかし、モッキング機能に karma.conf.js の mock フォルダーを使用できないかと思います。モック パーツをモック フォルダに移動して、すべての単体テストに使用することはできますか?
このフォルダーの例やドキュメントは見つかりませんでした。モック フォルダーの使用方法の例またはドキュメントを教えてください。