I'd like to run my first ever test of Angular app, but I have a huuuge problem with configuring it. Now I'm getting this error:
Error: [$injector:unpr] Unknown provider: responseProvider <- response <- MyFirstController
http://ift.tt/22W8nMi
at C:/StarterKit/08_AngularJS/angularStarterKit-master/bower_components/angular/angular.js:3994
at getService (C:/StarterKit/08_AngularJS/angularStarterKit-master/bower_components/angular/angular.js:4141)
at C:/StarterKit/08_AngularJS/angularStarterKit-master/bower_components/angular/angular.js:3999
at getService (C:/StarterKit/08_AngularJS/angularStarterKit-master/bower_components/angular/angular.js:4141)
at invoke (C:/StarterKit/08_AngularJS/angularStarterKit-master/bower_components/angular/angular.js:4173)
at instantiate (C:/StarterKit/08_AngularJS/angularStarterKit-master/bower_components/angular/angular.js:4190)
at C:/StarterKit/08_AngularJS/angularStarterKit-master/bower_components/angular/angular.js:8453
at C:/StarterKit/08_AngularJS/angularStarterKit-master/app/component-1/my-first.controller.spec.js:50
at C:/StarterKit/08_AngularJS/angularStarterKit-master/app/component-1/my-first.controller.spec.js:98
but I'm sure that as soon as I'll get rid of it, I will get another...
A part of my test file which contains config looks like that:
var ctrl,
fakeModal,
$scope,
_books_;
fakeModal = {
result: {
then: function(confirmCallback, cancelCallback) {
//Store the callbacks for later when the user clicks on the OK or Cancel button of the dialog
this.confirmCallBack = confirmCallback;
this.cancelCallback = cancelCallback;
}
},
close: function( item ) {
//The user clicked OK on the modal dialog, call the stored confirm callback with the selected item
this.result.confirmCallBack( item );
},
dismiss: function( type ) {
//The user clicked cancel on the modal dialog, call the stored cancel callback
this.result.cancelCallback( type );
}
};
_books_ = [
{
"genre": "Crime",
"year": 1965,
"title": "Sherlock Holmes",
"author": "Arthur Conan Doyle"
},
{
"genre": "Crime",
"year": 2005,
"title": "The girl with the dragon tattoo",
"author": "Stieg Larson"
}
];
beforeEach(module('app.component1'));
beforeEach(module('ngRoute'));
beforeEach(inject(function($controller, $rootScope){
$scope = $rootScope.$new();
ctrl = function() {
return $controller('MyFirstController', {
$scope: $scope,
$modal: fakeModal
});
};
}));
Module which contains tested Controller:
angular.module('app.component1', ['ngRoute','app.component1.templates'])
.config(['$routeProvider', function ($routeProvider) {
'use strict';
$routeProvider.when('/component-1/dialog-a', {
templateUrl: 'component-1/dialog-a/dialog-a.html',
controller: 'MyFirstController',
resolve: {
response: function($http){
return $http.get('/component-1/books.json');
}
}
});
}]);
and beginning of controller file:
angular.module('app.component1')
.controller('MyFirstController', function($scope, $http, $modal, response, transferBookService)
response argument is taken from module resolve part, and transferBookService is declared in the same file as controller.
How to inject this controller and how ctrl() should look like for me to be able to test everything I use in this controller?
Aucun commentaire:
Enregistrer un commentaire