私のコントローラで私のサービスを嘲笑するのに問題があるようです。特に 'momentsService'。ここに私のテストコードがあります。ジャスミンを使ったAngularJSサービスの模擬
最後の3つのconsole.logは、 'momentsService'に対して私に未定義を与え続けます。ターミナルでは、私は '定義されていないオブジェクトではない'だから私のサービスは正しく嘲笑されていないと私のテストは失敗を続けています。
コントローラとの依存関係:
(function() {
angular.module('app.MomentsController', [])
.controller('MomentsController', ['momentsService', '$scope', '$ionicContentBanner', 'core', 'components', '$q', '$ionicPopup', MomentsController]);
function MomentsController (momentsService, $scope, $ionicContentBanner, core, components, $q, $ionicPopup) {
var vm = this;
//Omitted
私はここで何をしないのですか?あなたの助けのための
おかげ
-Matt
EDIT: ことが重要ならば、私はcontrollerAs構文を使用しています。
EDIT2: これは、両方の修正を試みても、まだ動作しません。 momentsServiceは未定義です。次のように私のコードは、略:
describe('Moment Controller', function() {
var $scope, $controller, momentsService, $ionicContentBanner, core, components, $q, $ionicPopup;
beforeEach(module('app'));
beforeEach(module('core'));
beforeEach(module('components'));
beforeEach(module('constants'));
beforeEach(inject(function(_$controller_, $rootScope, _momentsService_, _$ionicContentBanner_, _core_, _components_, _$q_, _$ionicPopup_) {
var self = this;
this.$scope = $rootScope.$new();
this.momentsService = _momentsService_;
this.$ionicContentBanner = _$ionicContentBanner_;
this.core = _core_;
this.components = _components_;
this.$q = _$q_;
this.$ionicPopup = _$ionicPopup_;
spyOn(momentsService, 'initializeView');
this.$controller = _$controller_('MomentsController', {
momentsService: momentsService,
$scope: $scope,
$ionicContentBanner: $ionicContentBanner,
core: core,
component: components,
$q: $q,
$ionicPopup: $ionicPopup
});
}));
it('should initialize', function() {
console.log(this);
console.log("CONTROLLER");
console.log(this.momentsService);
console.log(this.momentsService.initializeView());
});
});
コメントで掲示plunkerがそれを使用していませんでしたので、私もthis
ずに試してみました。 this
を無視してコードが正確に投稿されたプランカに一致する場合、私は他の依存関係を追加したばかりです。コメントすると、私のサービスは未定義です。理解できません。
編集3:conf.jsで
'ファイルを':
files: [
'lib/ionic/js/ionic.bundle.js',
'lib/angular-mocks/angular-mocks.js',
'js/*',
'bestMoments/*',
'moments/*',
'submitMoment/*',
'myMoments/*',
'index.controller.js',
'layout/mainView.directive.js',
],
Moments.Service.jsの依存関係:
(function() {
angular.module('app.momentsService', [])
.service('momentsService', ['core', '$q', 'constants', 'awsServices', 'components', 'logger', 'geolocation', momentsService]);
function momentsService(core, $q, constants, awsServices, components, logger, geolocation){
http://jsfiddle.net/bowofola/s37266LL/2/ – Bowofola
あなたplunkerあなたは私の新しいコードを確認することができ、私のために動作しませんでしたか? – MatTaNg
どのモジュールがmomentsサービスで登録されていますか。 – Bowofola