[$injector:unpr] Unknown provider: dataProvider <- data

1,285 views
Skip to first unread message

Deva Anand

unread,
Oct 8, 2018, 11:36:00 AM10/8/18
to karma-users

I am trying to write some unit test for my app, but I am running into an issue.

My .js file looks like



function () {
angular
.module('app',[])
   
.factory('code', function ($http, svc, $q) {

         
function getCodeByID(id) {
           
return $http.get(svc.get('my-application') + id)
               
.then(function (res) {
                   
return res;
               
});
       
}

   
function getCodes(query) {
       
var qry = ccUtils.buildQuery(query);
       
return $http.get(svc.get('url')
           
.then(function (response) {
               
var resObj = {};
                resObj
.data = response.data.content;
                resObj
.pageData = {
                    totalPages
: response.data.totalPages,
                    totalElements
: response.data.totalElements
               
};
               
return resObj;
           
}));
   
}
       
});
})();




My spec.js file looks like.

describe('MyController', function() {
var data, svc, code;

// Set up the module
//beforeEach(module('app'));
beforeEach
(angular.mock.module('app'));

beforeEach
(inject(function(_data_) {
    data
= _data_;
}));

beforeEach
(inject(function(_svc_) {
    svc
= _svc_;
}));

beforeEach
(inject(function(_code_) {
    code
= _code_;
}));

it
('Should exist', function() {
    expect
(code).toBeDefined();
});

});




MyController
× Should exist
Error: [$injector:unpr] Unknown provider: dataProvider <- data
https://errors.angularjs.org/1.7.4/$injector/unpr?p0=dataProvider%20%3C-%20data
at node_modules/angular/angular.js:138:12
at node_modules/angular/angular.js:4905:19
at Object.getService [as get] (node_modules/angular/angular.js:5065:32)
at node_modules/angular/angular.js:4910:45
at getService (node_modules/angular/angular.js:5065:32)
at injectionArgs (node_modules/angular/angular.js:5090:58)
at Object.invoke (node_modules/angular/angular.js:5114:18)
at UserContext.WorkFn (node_modules/angular-mocks/angular-mocks.js:3439:20)
Error: Declaration Location
at window.inject.angular.mock.inject (node_modules/angular-mocks/angular-mocks.js:3402:25)
at Suite. (src/app/epcCodes/epc.spec.js:9:16)
at src/app/epcCodes/epc.spec.js:2:1



 

Deva Anand

unread,
Oct 8, 2018, 11:46:56 AM10/8/18
to karma-users
Can anyone help me in fixing with this issue

John J Barton

unread,
Oct 8, 2018, 12:03:56 PM10/8/18
to karma...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "karma-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to karma-users...@googlegroups.com.
To post to this group, send email to karma...@googlegroups.com.
Visit this group at https://groups.google.com/group/karma-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/karma-users/d9f335d6-8d8b-4a16-bcb0-a15ad01cec4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages