Jasmine Error when trying to set up controller object - angularjs

This is the actual error message that I receive:
Uncaught Error: [$injector:unpr] Unknown provider: formsProvider <- forms <- SignupAcclaimController
this is at the start of my test file:
describe("SignUp", function() {
describe("SignupAcclaimController", function () {
beforeEach(module('CL.SignUp'));
var controller, SignupService, $state, scope, identity;
beforeEach(inject(function (_$controller_, _$state_, _SignupService_, _$rootScope_, _identity_) {
$state = _$state_;
scope = _$rootScope_.$new();
SignupService = _SignupService_;
identity = _identity_;
controller = _$controller_('SignupAcclaimController', {
$state: $state,
SignupService: SignupService,
identity: _identity_,
detailsForm: mocks.form
});
}));........
The error occurs when trying to set controller. mocks.form has been declared above this code.
The actual controller is:
(function() {
'use strict';
angular.module('CL.SignUp')
.controller('SignupAcclaimController', SignupAcclaimController);
SignupAcclaimController.$inject = ['$window', '$state', '$log', 'SignupService', 'identity', 'detailsForm', 'forms', '$rootScope', '$scope', '$timeout'];
function SignupAcclaimController($window, $state, $log, SignupService, identity, detailsForm, forms, $rootScope, $scope, $timeout) {
var vm = this, ........
If I change the injector functions signature to be the same as the method signature of the actual controller then expand the controller = to be
controller = _$controller_('SignupAcclaimController', {
$window: _$window_,
$state: $state,
$log: $log,
SignupService: SignupService,
identity: _identity_,
detailsForm: mocks.form,
forms: _forms_,
$scope: scope,
$rootScope: _$rootScope_,
$timeout: _$timeout_
then the error changes to :
Uncaught Error: [$injector:unpr] Unknown provider: formsProvider <- forms

Related

Scope variable how to access in jasmine framework using angularjs

I injected controller all dependencies into spec.js file and trying to access the scope variable but am getting TypeError: Cannot read property 'itemsByPage' of undefined spec.js file mocked below;
`describe('baseController', function() {
beforeEach(module('seApp'));
var $controller,$scope,$compile, $timeout, $mdSidenav, $log,
$http,$uibModal, $routeParams, $window,$mdDialog;
inject(function($controller,$rootScope,$compile, $timeout,$mdSidenav,
$log, $http,$uibModal, $routeParams, $window,$mdDialog){
$scope = $rootScope.$new();
$compile = $compile,
$timeout =$timeout,
$mdSidenav =$mdSidenav,
$log = $log,
$http = $http,
$routeParams = $routeParams,
$window = $window,
$mdDialog =$mdDialog,
$uibModal = $uibModal;
baseController = $controller('baseController', {
$scope : $scope,
$compile : $compile,
$timeout :$timeout,
$mdSidenav :$mdSidenav,
$log : $log,
$http : $http,
$routeParams : $routeParams,
$window : $window,
$mdDialog : $mdDialog,
$uibModal : $uibModal
});
});
it('check the base controller', function() {
expect(1).toBe(1);
});
describe('check scope', function() {
it('check itemsBy page', function() {
expect($scope.itemsByPage).toEqual('8');
}); });});`
execution report is Executed 2 of 2 (1 FAILED) controller is passing but not able to access scope variable inside the controller. please suggest me am new for jasmine framework

Unit test Karma -Unknown provider

I'm writing unit tests for my project built on Angularjs with Karma-jasmine. I'm using x-editable library in my app.
I'm trying to unit test a controller which depends on the x-editable library.
But I'm facing the error below :
Error: [$injector:unpr] Unknown provider: editableThemesProvider <- edit ableThemes
I have already added the path of x-editable my in Karma config file :
files:[
......
{ pattern: '../../libs/angular/angular-xeditable/dist/js/xeditable.min.js', watched: false },
........
]
Below the spec file :
beforeEach(inject(function(_$controller_, $rootScope, $localStorage, _editableThemes_, _editableOptions_) {
localStorage = $localStorage;
$controller = _$controller_;
editThemes = _editableThemes_;
editOptions = _editableOptions_;
scope = $rootScope.$new();
leaderboardCtrl = $controller('LeaderboardCtrl', {
$scope: scope,
$modal : modal,
$q: q,
editableOptions: editOptions,
editableThemes: editThemes,
$localStorage: localStorage,
LeaderBoardService : leaderboardService
});
}));
And this is my controller file :
(function() {
'use strict';
angular
.module('app')
.controller('LeaderboardCtrl', leaderboardCtrl);
leaderboardCtrl.$inject = ['$scope', '$q', '$modal', '$localStorage', 'editableOptions', 'editableThemes', 'LeaderBoardService'];
function leaderboardCtrl ( $scope, $q, $modal, $localStorage, editableOptions, editableThemes, LeaderBoardService) {
var event_ID = $localStorage.currentEventId;
editableThemes.bs3.inputClass = 'input-sm';
editableThemes.bs3.buttonsClass = 'btn-sm';
editableOptions.theme = 'bs3';
What am I doing wrong? did i missed something?

Error: [$injector:unpr] Unknown provider: RestaurantListServiceProvider <- RestaurantListService <- ReservationController

Here I have my RestaurantList service as follows
var restaurantList = angular.module("service.restaurantList", []);
restaurantList.service('RestaurantListService', ['$rootScope', 'BackendService', 'toaster', '$cookieStore', 'getConstants', 'principal', '$state',
function ($rootScope, BackendService, toaster, $cookieStore, getConstants, principal, $state) {
/*
*/
}])
I have my code for the reservation.js as follows
var app = angular.module('reservation', ['angularMoment']);
app.controller('ReservationController',['$scope', 'ngDialog', 'BackendService','ReservationService','RestaurantListService', '$rootScope', 'toaster', "$timeout", "checkEmpty",
"$interval", "principal",
function ($scope, ngDialog, BackendService, ReservationService,RestaurantListService, $rootScope, toaster, $timeout, checkEmpty, $interval, principal) {
/*
*/
}])
In the Reservation Controller I am injecting ReservationList service. Now it gives the error
angular.js:12798 Error: [$injector:unpr] Unknown provider: RestaurantListServiceProvider <- RestaurantListService <- ReservationController
That error is coming because you are having your service defined in a separate module. Here you are defining two modules for your application ('service.restaurantList' & 'reservation') . Try to add the dependency of child module in to your parent module like this.
var app = angular.module('reservation', ['angularMoment', 'service.restaurantList']);

Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope Error

I am getting this common error Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope with my test case . I know this is a common one , and there are few other threads explaining with solutions . But i really couldn't come up with a answer to my problem . Can anyone point me in the right direction?
ViewMeetingCtrl ,
(function () {
'use strict';
angular.module('MyApp').controller('ViewMeetingCtrl', ViewMeetingCtrl);
ViewMeetingCtrl.$inject = ['$scope', '$state', '$http', '$translate', 'notificationService', 'meetingService', '$modal', 'meeting', 'attachmentService'];
function ViewMeetingCtrl($scope, $state, $http, $translate, notificationService, meetingService, $modal, meeting, attachmentService) {
$scope.meeting = meeting;
$scope.test = "testvalue";
if (meeting.Status == 'Cancelled')
{
$scope.actionButtons = false;
}
else
{
$scope.actionButtons = true;
}
//more code
}
})();
MeetingCtrlSpec.js
describe('ViewMeetingCtrl', function () {
var $rootScope, scope, $controller, meetingService;
beforeEach(angular.mock.module('MyApp'));
beforeEach(inject(function ($rootScope, $controller, meetingService) {
scope = $rootScope.$new();
$controller('ViewMeetingCtrl', {
meetingService: meetingService,
'$rootScope' : $rootScope,
scope: scope
});
}));
it('should change greeting value if name value is changed', function () {
//some assertion
});
});
Error trace :
Firefox 37.0.0 (Windows 8.1) ViewMeetingCtrl should change greeting value if name value is changed FAILED
Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- ViewMeetingCtrl
http://errors.angularjs.org/1.3.15/$injector/unpr?p0=%24scopeProvider%20%3C-%20%24scope%20%3C-%20ViewMeetingCtrl
minErr/<#C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:63:12
createInjector/providerCache.$injector<#C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/ang
ular/angular.js:4015:19
getService#C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:4162:39
createInjector/instanceCache.$injector<#C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/ang
ular/angular.js:4020:28
getService#C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:4162:39
invoke#C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:4194:1
instantiate#C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:4211:27
$ControllerProvider/this.$get</<#C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/an
gular.js:8501:18
angular.mock.$ControllerDecorator</<#C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/node_modules/angular-mo
cks/angular-mocks.js:1878:12
#C:/Users/dell pc/Documents/Work/MyApp/FLIS.Client.Tests/test/company/MeetingCtrlSpec.js:8:1
invoke#C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/bower_components/angular/angular.js:4203:14
workFn#C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/node_modules/angular-mocks/angular-mocks.js:2436:11
angular.mock.inject#C:/Users/dell%20pc/Documents/Work/MyApp/WebApiRole/node_modules/angular-mocks/angular-mocks
.js:2407:25
#C:/Users/dell pc/Documents/Work/MyApp/Client.Tests/test/company/MeetingCtrlSpec.js:6:16
#C:/Users/dell pc/Documents/Work/MyApp/Client.Tests/test/company/MeetingCtrlSpec.js:1:1
Firefox 37.0.0 (Windows 8.1): Executed 3 of 3 (1 FAILED) (0.094 secs / 0.091 secs)
Replace
$controller('ViewMeetingCtrl', {
meetingService: meetingService,
'$rootScope' : $rootScope,
scope: scope
});
by
$controller('ViewMeetingCtrl', {
meetingService: meetingService,
$scope: scope
});
The controller must be injected with an argument named $scope, not scope. And $rootScope is not part of the injected collaborators of your controller.
Same error I had forget to put '$' before scope in
app.controller("loginCtrl", function(**$**scope){
})

Angularjs Controller test giving TypeError: undefined is not a function

.controller('ClientsCtrl', ['$scope', '$location', '$filter', '$modal', 'ngTableParams',
function($scope, $location, $filter, $modal, ngTableParams) {
var trowser = PY.getBooks($scope, $location, $modal);
};
controllertestspec.js
'use strict';
describe('suite', function() {
var scope, ctrl;
beforeEach(module('clients'));
beforeEach(inject(function($controller) {
scope = {};
var modalInstance = jasmine.createSpy('fakeModal');
ctrl = $controller('ClientsCtrl', {
$scope: scope,
$modal: modalInstance
});
}));
it('should change greeting value if name value is changed', function() {
});
});
I have added the js file having module PY and if i try to print console.log(typeof PY.Books) it shows as function.
When i tried to run the spec file am getting error
Chrome 39.0.2171 (Mac OS X 10.9.5) clients module should change greeting value if name value is changed FAILED
TypeError: undefined is not a function
at Object.PY.getBooks

Resources