samedi 7 février 2015

Error with unit tests in AngularJS - controller with many dependency

I have some problem with unit test in AngularJS. I took from github angular seed app and wrote some modules. And now when i try to test it I have error. Problem is only in unit test - in browser app is working correctly.


I feel that it should be something easy to resolve, but I can't find where I make mistake.


My controller:



'use strict';
angular.module('myApp.student', ['ngRoute'])

.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/student', {
templateUrl: 'student.html',
controller: 'StudentCtrl'
});
}])
.controller('StudentCtrl', ['$scope', '$http', '$modal', '$log', function($scope, $http, $modal, $log) { ... }]);


My unit test dokumenty_test.js:



describe('myApp.student', function() {
beforeEach(module('myApp.student'));

describe('StudentCtrl controller', function(){

it('should ....', inject(function($controller) {
//spec body
var view1Ctrl = $controller(StudentCtrl');
expect(view1Ctrl).toBeDefined();
}));

});
});


And the error from console: Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope http://ift.tt/1wjqV6m$injector/unpr?p0=%24scopeProvider%20%3C-%20%24scope


Thanks in advance


Aucun commentaire:

Enregistrer un commentaire