Reputation: 4745
Error: [$injector:unpr] Unknown provider: $localStorageProvider <- $localStorage
I'm getting an error when I run my jasmine test with Karma. I'm unsure of how to handle it, I tried placing localstorage in my injection in my jasmine file but no luck. All I want to do is make sure my controller is being recognized by my Jasmine file to start.
Javascript file:
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 file:
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();
});
});
});
Update 1: Interestingly enough, if I comment out my it block, the test runs without error.
Upvotes: 0
Views: 1051
Reputation: 1718
you have to inject ng storage before module('angularTemplateApp');
like beforeEach(module('ngStorage'));
provided you have added localstorage file to your configuration file i.e ngStorage.min.js
Upvotes: 1