Error: [$injector:unpr] Unknown provider: DSCacheFactoryProvider <- DSCacheFactory <- myService

1,027 views
Skip to first unread message

Guru I

unread,
Aug 10, 2014, 2:17:38 PM8/10/14
to angula...@googlegroups.com
Implemented angular-cache for certain time consuming http request in my app.  App works great but seems my unit tests are failing with above error...

in karma.conf.js i added this
'app/bower_components/angular-cache/dist/angular-cache.js',

1) I added 'angular-data.DSCacheFactory' as dependency in my app.js
2) Implemented dataServiceCache which uses DSCacheFactory to create, remove cache
3) I have dataService which depends on dataServiceCache now.


Everything works fine except my unit tests for controllers (which depends on dataService - which depends on dataServiceCache) are failing. 

Any ideas what mistake im doing here.




dataServiceCache.js -

angular.module('emcdApp')
.factory('dataServiceCache', function(DSCacheFactory){
var dataServiceCache = {};
///code...
/////....

                return dataServiceCache;
});

Guru I

unread,
Aug 11, 2014, 7:21:36 PM8/11/14
to angula...@googlegroups.com
I am still having this issue and im clueless 

Im loading angular-cache after angular.js
while i did not understand this statement

Angular-cache is a dependency of angular-data and must be loaded before angular-data if you are using angular-data.

Do i need angular-data to be installed. Without angular-data my application runs fine, although i have dependency in my app.js as angular-data.DSCacheFactory


Jason Dobry

unread,
Aug 11, 2014, 11:03:35 PM8/11/14
to angula...@googlegroups.com
No, you don't need angular-data.js to use angular-cache. Can I see your karma.conf.js and (if you have one) karma.start.js to help you debug?

Guru I

unread,
Aug 12, 2014, 10:05:14 AM8/12/14
to angula...@googlegroups.com
basePath: '',

    // testing framework to use (jasmine/mocha/qunit/...)
    frameworks: ['jasmine'],
    reporters: ['progress', 'junit'],

    preprocessors: {
      'app/views/**/*.html': ['ng-html2js'],
      'test/views/**/*.html': ['ng-html2js'],
      '.tmp/views/**/*.html': ['ng-html2js'],
      '**/*.coffee' : ['coffee']

    },
    // list of files / patterns to load in the browser
    files: [
      'app/bower_components/jquery/dist/jquery.js',
      'app/bower_components/jasmine-given/dist/jasmine-given.js',
      'app/bower_components/jasmine-stealth/dist/jasmine-stealth.js',
      'app/bower_components/big.js/big.js',
      'app/bower_components/momentjs/moment.js',
      'app/bower_components/angular/angular.js',
      '.tmp/scripts/**/*.js',
      'app/bower_components/angular-touch/angular-touch.js',
      'app/bower_components/angular-cookies/angular-cookies.js',
      'app/bower_components/angular-mocks/angular-mocks.js',
      'app/bower_components/angular-ui-router/release/angular-ui-router.js',
      'app/bower_components/angular-translate/angular-translate.js',
  'app/bower_components/angular-cache/dist/angular-cache.js',
      'app/scripts/*.js',
      'app/scripts/**/*.js',
      'test/mock/**/*.js',
      'test/spec/**/*.js',
      'test/views/**/*.html',
      'app/views/**/*.html',
      '.tmp/views/**/*.html' //jade overides html
    ],

What i was able to do is to inject a mock of my dataServiceCache which use DSCacheFactory

// load the controller's module
var dataServiceCacheMock;

beforeEach(function(){
module('myApp', function($provide){
$provide.value('dataServiceCache', dataServiceCacheMock);
});
});

Gaurav Inamdar

unread,
Aug 14, 2014, 11:25:20 AM8/14/14
to angula...@googlegroups.com
Hi

Sorry for this whole confustion, i managed to get my unit tests working again, apparently i was missing the DI in one of my init.js file which is used when i do beforeEach(module('myApp));

I added the dependency there and now all UT passes without any other code change.


--
You received this message because you are subscribed to a topic in the Google Groups "angular-cache" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular-cache/ms3S7ARq9Us/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular-cach...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason Dobry

unread,
Aug 14, 2014, 11:42:39 AM8/14/14
to Gaurav Inamdar, angula...@googlegroups.com
Good to hear


--
You received this message because you are subscribed to the Google Groups "angular-cache" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular-cach...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Jason Dobry
jason...@gmail.com

NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
Reply all
Reply to author
Forward
0 new messages