0
Error: [$injector:unpr] Unknown provider: $localStorageProvider <- $localStorage
カルマでジャスミンテストを実行するとエラーが発生します。私はそれを扱う方法がわからないので、私は自分のジャスミンファイルに私の注射でlocalstorageを配置しようとしましたが、運はありませんでした。私がやりたがっていることは、私のジャスミンファイルがコントローラを認識していることを確認することだけです。
のJavascriptファイル:
define(['app'], function (app) {
'use strict';
app.controller('SplashController',
function ($scope, $state, $localStorage, $window, $modal, pageService, authenticationService, focusService, config) {
var state;
focusService.focusMain();
$scope.beginLogon = function() {
authenticationService.authenticate();
};
$scope.checkMedia = function (state) {
$state.transitionTo(state);
};
$scope.today = new Date();
$scope.appTitle = config.app.title;
var loc = $window.location.pathname;
var url = $window.location.origin;
var modalInfo = {value: null, dismissed: true, resendHash: []};
var modalInstance;
var controller;
var openModal = function (template, controller, modalInfo) {
modalInstance = $modal.open({
windowTemplateUrl: 'src/ui-components/modals/helper/modal-window_template.html',
templateUrl: template,
controller: controller,
backdrop: 'static',
keyboard: false,
resolve: {
modalInfo: function() {
return modalInfo;
}
}
});
};
$scope.previewCloseClick = function() {
$modalInstance.close();
modalInfo.dismissed = true;
};
var ModalInstanceCtrl = function ($scope, focusService) {
modalInfo.dismissed = false;
focusService.focusTopModal();
$scope.okCancel = function() {
modalInstance.close();
modalInfo.dismissed = true;
};
};
});
});
specファイル:
define(['SplashController'], function() {
'use strict';
describe("The Splash Controller", function() {
var controller,
scope,
localStorage;
beforeEach(function() {
module('angularTemplateApp');
focusServiceMock = jasmine.createSpyObj('focusService', ['focusMain']);
module(function ($provide) {
$provide.value('focusService', focusServiceMock);
$provide.value('authenticationService', authServiceMock);
});
inject(function ($controller, $rootScope, $localStorage) {
localStorageMock = jasmine.createSpyObj('$localStorage', ['openModal']);
scope = $rootScope.$new();
localStorage = $localStorage;
controller = $controller('SplashController', {
$scope: scope,
$localStorage: localStorage
});
});
});
it("when the login button is clicked", function() {
expect(controller).toBeDefined();
});
});
});
アップデート1:私はそれのブロックをコメントアウトする場合興味深いことに、テストはエラーなしで実行されます。インスタンス化に失敗しました:あなたはあなたを提供beforeEach(module('ngStorage'));
ようmodule('angularTemplateApp');
前ngのストレージを注入する必要が
が私のために動作しませんでした。すなわち、私が得るあなたの設定ファイルにのlocalStorageファイルを追加しましたモジュールngStorageは ですが、jsファイル自体にngStorageは使用しません。 – Snorlax