angular-xeditable icon indicating copy to clipboard operation
angular-xeditable copied to clipboard

Unit test Karma -Unknown provider

Open IssamEssarghini033 opened this issue 8 years ago • 8 comments

I'm writing unit tests for my project built on Angularjs with Karma-jasmine.

I'm trying to unit test a controller which depends on the angular-xeditable library. But I'm facing the error below :

Error: [$injector:unpr] Unknown provider: editableThemesProvider <- editableThemes

I have already added the path of x-editable my in Karma config file :

files:[ 
    ...
    { pattern: '../../libs/angular/angular-xeditable/dist/js/xeditable.min.js', watched: false },
     ...
    ]

Below the spec file :

beforeEach(inject(function(_$controller_, $rootScope, $localStorage, _editableThemes_, _editableOptions_) {
 localStorage = $localStorage;
 $controller = _$controller_;
 editThemes = _editableThemes_;
 editOptions = _editableOptions_;
 scope = $rootScope.$new();
 leaderboardCtrl = $controller('LeaderboardCtrl', {
  $scope: scope,
  $modal : modal,
  $q: q,
  editableOptions: editOptions,
  editableThemes: editThemes,
  $localStorage: localStorage,
  LeaderBoardService : leaderboardService
});
}));

And this is my controller file :


  leaderboardCtrl.$inject = [..., 'editableOptions', 'editableThemes', ...];

function leaderboardCtrl  ( ...,  editableOptions,   editableThemes, ...) {
...
  editableThemes.bs3.inputClass = 'input-sm';
  editableThemes.bs3.buttonsClass = 'btn-sm';
  editableOptions.theme = 'bs3';
...

What am I doing wrong? did i missed something?

IssamEssarghini033 avatar Nov 22 '16 16:11 IssamEssarghini033

Does your app work correctly, just the tests fail?

ckosloski avatar Nov 22 '16 16:11 ckosloski

@ckosloski yeah the app works properly 👍

IssamEssarghini033 avatar Nov 22 '16 16:11 IssamEssarghini033

How are you injecting xeditable into your tests?

ckosloski avatar Nov 22 '16 17:11 ckosloski

i've added the path of xeditable in my karma conf file, and i inject it by

beforeEach(inject(function(..., _editableThemes_, _editableOptions_) {

editThemes = _editableThemes_;
 editOptions = _editableOptions_;

Because in my Controller i'm usiing editableThemes and editableOptions services that's why I injected them.

IssamEssarghini033 avatar Nov 22 '16 17:11 IssamEssarghini033

Don't you need to inject xeditable? How do you inject xeditable into your application?

ckosloski avatar Nov 22 '16 17:11 ckosloski

Actually i'm using oc.lazyload, when i redirect to the view where i'm using xeditable, i load it in my router config by :

resolve: load([
  'xeditable',

and on lazyload config i have :

{
          name: 'xeditable',
          files: [
              'libs/angular/angular-xeditable/dist/js/xeditable.min.js',
              'libs/angular/angular-xeditable/dist/css/xeditable.min.css'
          ]
      },

On My controller i inject only editableThemes and editableOptions. and it works fine.

IssamEssarghini033 avatar Nov 22 '16 18:11 IssamEssarghini033

I am not familiar with this, but I would think that you would still need to load xeditable in your test somehow (unless you are saying lazyload does that for your test as well)

ckosloski avatar Nov 22 '16 19:11 ckosloski

@IssamEssarghini033 did you ever figure out your problem?

ckosloski avatar Aug 11 '17 19:08 ckosloski