2016-11-02 4 views
0

Я полный новичок с тестированием AngularJS, поэтому любые предложения оцениваются!

Я получаю сообщение об ошибке, когда я пытаюсь и запустить Карма Start, который выглядит, как этого

Chrome 54.0.2840 (Mac OS X 10.11.6) DashboardCtrl Should Exist FAILED 
Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- DashboardCtrl 
http://errors.angularjs.org/1.5.8/$injector/unpr?p0=%24scopeProvider%20%3C-%20%24scope%20%3C-%20DashboardCtrl 
    at node_modules/angular/angular.js:68:12 
    at node_modules/angular/angular.js:4511:19 
    at Object.getService [as get] (node_modules/angular/angular.js:4664:39) 
    at node_modules/angular/angular.js:4516:45 
    at getService (node_modules/angular/angular.js:4664:39) 
    at injectionArgs (node_modules/angular/angular.js:4688:58) 
    at Object.instantiate (node_modules/angular/angular.js:4730:18) 
    at $controller (node_modules/angular/angular.js:10369:28) 
    at node_modules/angular-mocks/angular-mocks.js:2221:12 
    at Object.<anonymous> (www/tests/dashboard.spec.js:9:19) 
Error: Declaration Location 
    at window.inject.angular.mock.inject (node_modules/angular-mocks/angular-mocks.js:3047:25) 
    at Suite.<anonymous> (www/tests/dashboard.spec.js:7:13) 
    at www/tests/dashboard.spec.js:1:1 
Expected undefined to be defined. 
    at Object.<anonymous> (www/tests/dashboard.spec.js:13:25) 

My Dashboard Controller выглядит следующим образом

angular.module('myApp.controllers', []) 
.controller('DashboardCtrl', function($rootScope, $scope, API, $ionicModal, $window, $ionicLoading) { 

С некоторым содержанием и все необходимое закрытием теги ниже;)

Мой тестовый код выглядит так

describe('DashboardCtrl', function(){ 
var $controller, DashboardCtrl; 

beforeEach(angular.mock.module('ui.router')); 
beforeEach(angular.mock.module('myApp.controllers')); 

beforeEach(inject(function(_$controller_){ 
    $controller = _$controller_; 
    DashboardCtrl = $controller('DashboardCtrl', {}); 
})); 

it('Should Exist', function(){ 
    expect(DashboardCtrl).toBeDefined(); 
}) 
}); 

Я видел некоторые другие сообщения об этом, но я просто не могу понять, где я иду не так, спасибо за любую помощь заранее всех!

+0

Вы должны вводить зависимости в контроллер – devqon

+0

Спасибо, что избавились от ошибок, однако, она прекратила свои функции $ rootScope от работы в контроллер, просто интересно, нужно ли мне также вводить rootScope? если так это делается по-другому? – BRollinson

+0

if (! $ RootScope.isSessionActive()) { \t \t $ window.location.href = (''); } – BRollinson

ответ

0

Вы забываете, чтобы создать и внедрить $scope

describe('DashboardCtrl', function(){ 
    var $scope, 
     DashboardCtrl; 

    beforeEach(angular.mock.module('ui.router')); 
    beforeEach(angular.mock.module('myApp.controllers')); 

    beforeEach(inject(function($rootScope, $controller){ 
     $scope = $rootScope.$new(); 

     DashboardCtrl = $controller('DashboardCtrl', { 
      $scope: $scope 
     }); 
    })); 

    it('Should Exist', function(){ 
     expect(DashboardCtrl).toBeDefined(); 
    }) 
}); 
Смежные вопросы