Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing Angular Service gives error: No module: ngResource

I have yeoman-angular set up with the following app:

angular.module('myApp', ['ngResource','ui.bootstrap'])
  .config(['$routeProvider', function ($routeProvider) {
      $routeProvider
      ...
  }]);

and a service:

angular.module('myApp')
  .factory('UserSvc', [function() {
        return {
            name : '',
            topicOrder: 'lec_type',
        };
    }]);

and the following test:

describe('Service: UserSvc', function () {

  beforeEach(module('mfApp'));

  var UserSvc;
  beforeEach(inject(function(_UserSvc_) {
    UserSvc = _UserSvc_;
  }));

  it('should do something', function () {
    expect(UserSvc.topicOrder).toEqual('lec_type');
  });

});

I've tried my best to inject $resource in the test (although the srvice itself isn't denpend on ngResource), but when I run the test, I get this error

Error: No module: ngResource

if I remove the dependencies from the module itself,

angular.module('myApp', [])

then the tests run successfully

I've really tried everything but failed

like image 635
qais Avatar asked Mar 27 '13 11:03

qais


2 Answers

in your testacular.conf.js / karma.conf.js did you include angular-resource.js; e.g.

files = [
  JASMINE,
  JASMINE_ADAPTER,
  'app/vendor/angular/angular.js',
  'app/vendor/angular/angular-*.js',
like image 174
Mark Nadig Avatar answered Oct 18 '22 06:10

Mark Nadig


After including your new component, remember to restart your Testacular/Karma session.

like image 21
Vitae Aliquam Avatar answered Oct 18 '22 07:10

Vitae Aliquam