lundi 16 novembre 2015

Error: $injector:unpr AngularJS Testing mocking object instances

I keep running into problems at the minute when i'm testing my AngularJS applications, I try and inject all dependencies however it doesn't seem to be working, any help is greatly appreciated :)

It's quite a large application and i'm trying to break things down as much as possible and test them, however we have a factory called firebaseUser which is, as you can guess a firebaseUser. We also have an instance of this known as userInstance so I'm getting errors whenever I try and mock userInstance.

describe('Dashboard Start Controller', function () {

  var scope, ctrl;

  beforeEach(function () {
    MockFirebase.override();
    module('noodleApp.start');
    module('noodleApp.noodleFactory');
    module('noodleApp.firebaseUser');
    module('noodleApp.start');
  });

  beforeEach(inject(function($rootScope, $controller, $injector) {
    scope = $rootScope.$new();
    ctrl = $controller('StartController', {$scope: scope});
  }));

  afterEach(function () {
    scope.$destroy();
  });

  it('should be available', function() {
    expect(ctrl).toBeDefined();
  });

  it('should init with filter being set to all', function() {
    expect(scope.filterOn).toBe('all');
  });
});

Whenever I run this test I get the following error: Unknown provider: userInstanceProvider <- userInstance <- StartController

Aucun commentaire:

Enregistrer un commentaire