Error: [$injector:unpr] Unknown Provider: $scopeProvider <- $Scope

Asked

Viewed 537 times

0

I am getting the following error while running my test:

Error: [$injector:unpr] Unknown Provider: $scopeProvider <- $Scope

Logincontroller.js

(function(){
'use strict'; 

angular.module("app")
    .controller('LoginController', LoginController);

LoginController.$inject = ['$scope', '$rootScope', '$controller', 'EntryPointService', 'initResolver'];

function LoginController($scope, $rootScope, $controller, EntryPointService, initResolver){
    $controller('BaseController', { $scope: $scope });

    var initialize = function(logged, stateName) {
        if(logged && stateName === 'login') {
            $scope.$state.go('master.modules');
        } 

        if ($scope.$state.is('logout')) {
            $scope.showLogoutPopup();
        }
    };

    initialize($rootScope.operator_logged, $scope.$state.$current.name);

    if([null, undefined].indexOf(initResolver) !== -1){
        $scope.$state.go('init');
    }

    $scope.STCPAppVer = $scope.StcpUtilsService.getAppVersionToView();

Logincontroller.Spec

   describe('LoginController test suite', function(){    
   beforeEach(angular.mock.module('app'));                             

   var $scope, controller, state, base, rootScope, httpBackend, scope;

   var fakeRequest = function(){
       return;
  }; 

  beforeEach(angular.mock.inject(function($controller, $rootScope, $state, 
  $httpBackend, $scope){      
      state = {};
      state.go = sinon.stub();
      state.$current = {};
      $scope = $rootScope.$new();
      $scope.showLogoutPopup = sinon.stub();
      $scope.$state = state;
      $scope.$state.is = function(val){ return $scope.$state.$current.name === val; };
       rootScope = $rootScope;
      $scope.showLogoutPopup = sinon.stub();
      base = $controller('LoginController', { $scope: $scope, $state: state 
});
      controller = $controller;
      httpBackend = $httpBackend;
      scope = $scope;

  }));

    it('function LoginController', function(){

  });

What is missing? Why is this error occurring?

  • That’s all the code you have?

  • 1

    think your $Scope statement is giving conflict. var $Scope. Third line of Logincontroller.Spec

  • As Ccastro said, it must be this variable that is giving error in Scope, try to take the $Scope from the inject and change the variable name to another

  • The following error appeared when removing $Scope: Error: [$injector:unpr] Unknown Provider: initResolverProvider <- initResolver <- Logincontroller @Ccastro

  • @LINQ no, I just sent a part.

  • The following error appeared when removing $Scope: Error: [$injector:unpr] Unknown Provider: initResolverProvider <- initResolver <- Logincontroller @Julioborges

  • What is this initResolver? something you wrote? If so, it, q must be an initResolver.js, has q be included there in your index.html

  • Ccastro it is already included but the error persists

  • 1

    You removed $Scope from inject? If so, return it to inject, but do not declare on var.

  • @Ccastro the tips were followed but nothing changed

  • If you want to upload the code to some git I take a look.

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.