Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing Angular using Angular Mocks: Provider '$$sanitizeUri' must define $get factory method

I'm testing my application using Angular Mocks and when it tries to create some module I have this issue.

describe('navRegisterOverrideSpec', function () {
  var navigationServiceProvider;

  beforeEach(module('wrapper'));

  describe('remove un needed navs', function () {
    var navigationService;

    beforeEach(
      inject(function ($injector) {
        navigationService = $injector.get('navigationService');
      }));

    it('Should not have admin menu', function () {
      var filtered = _.filter(navigationService.items, function (item) {
        return item.id == 'admin_menu';
      });

      expect(filtered.length).toEqual(0);
    });
  });
});

Below is the error I got.

Error: [$injector:modulerr] Failed to instantiate module ng due to:
Error: [$injector:pget] Provider '$$sanitizeUri' must define $get factory method.
http://errors.angularjs.org/1.5.5/$injector/pget?p0=%24%24sanitizeUri
    at provider (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:4497)
    at D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:366
    at forEach (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:336)
    at D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:4484
    at ngModule (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:2530)
    at invoke (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:4665)
    at runInvokeQueue (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:4558)
    at D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:4567
    at forEach (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:322)
    at loadModules (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:4590)
    at createInjector (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular/angular.js:4470)
    at workFn (D:/Projects/l35workflow/src/portals/verybest/bower_components/angular-mocks/angular-mocks.js:2464)
http://errors.angularjs.org/1.5.5/$injector/modulerr?p0=ng&p1=Error%3A%20%5B%24injector%3Apget%5D%20Provider%20'%

I cannot find any answer out there. Any help would be appreciated.

like image 654
Justin Chasez Avatar asked Nov 08 '22 16:11

Justin Chasez


1 Answers

I was running into this very same issue and stumbled upon this github issue which then lead me to the linked github issue. I have no idea whether or not you are using karma as your test runner and phantom as your headless web browser but updating my karma-phantomjs-launcher to ^1.0.0 ultimately solved my issue.

Reason for the issue (for those who don't want to go through the links I mentioned above) is that PhantomJS is not officially supported by the Angular and in turn the older version of the karma-phantomjs-launcher was using an older web engine that handled new/bind differently than what Angular is used to.

like image 87
wootencl Avatar answered Nov 15 '22 06:11

wootencl