Here is the starting point for the controller code:
angular
.module('hc.hotelContent')
.controller('NameLocationController', nameLocationCtrlFn); //Todo change hotelDataService
nameLocationCtrlFn.$inject = ['$stateParams', 'hotelDataService'];
function nameLocationCtrlFn($stateParams, hotelDataService) {
var vm = this,
hotelId = $stateParams.hotelId;
vm.Keys = {
Name: 'Name',
Street: 'Street',
City: 'City',
State: 'State',
Zip: 'Zip',
Country: 'Country'
}
}
I have additional code as well but it doesn't affect the logic. My tests work fine without injecting $stateParams into the controller.
Now, here's the Test file:
describe('nameLocation component Controller', function () {
var $controller,
hotelDataServiceMock,
stateParams,
hotelId = "4611";
Keys = {
Name: 'Name',
Street: 'Street',
City: 'City',
State: 'State',
Zip: 'Zip',
Country: 'Country'
}//@
beforeEach(module('hc.hotelContent'));
beforeEach(module('hc.app.core'));
beforeEach(inject(injectFn));
function injectFn(_$controller_, $stateParams, _hotelDataService_) {
$controller = _$controller_;
stateParams = $stateParams;
hotelDataServiceMock = _hotelDataService_;
} //controller injection fn
function initCtrl() {
controller = $controller('NameLocationController', {
$stateParams: stateParams,
hotelDataService: hotelDataServiceMock
});
}
describe('inserting a new hotel', function () {
it('should populate Keys object', function () {
var controller = initCtrl();
expect(controller.Keys).toEqual(Keys);
});
}
}
I'm encountering an Unknown Provider error. This issue doesn't seem to be related to my controller because all I'm doing in the controller is assigning the variable to the $stateParams variable. How can I resolve this injection problem? My karma.conf file is configured to load jQuery, Angular, UI-Router, and mocks in that particular order and then all the JavaScript and HTML files.
Edit: Prior to this, I came across this post, but despite adding beforeEach(module('hc.app')); to the code since I'm using UI-Router in my main app module, the issue still persists