lundi 4 septembre 2017

Jasmine can't find a injected var inside injected module

I have the following scenario:

A test class with the goal is validade my directive...

describe('Directive Spec', function() {

    var $compile, $rootScope, directives;

    beforeEach(module('ui-first', 'ui-first.directive'));

    beforeEach(module(function(_$provide_) {
        _$provide_.value('$commons');
    }));

    beforeEach(inject(function(_$compile_, _$rootScope_) {
        $compile = _$compile_;
        $rootScope = _$rootScope_;
        directive = $compile("<ui-pop-dir></ui-pop-dir>")($rootScope);
        $rootScope.$digest();
    }));

    it('blablabla', function() {...});
});

ui-first is my module and ui-first.directive my template declaration in karma.conf.js.

In my directive, i have a "inject" declaration for my controller...

Controller.$inject = ['$scope', '$commons'];

Inside my "$commons", i have a injector...

var promisseT = $injector.get('promisseT');

When i run my tests, Jasmine can't find my "$commons" and the tests fail...

TypeError: undefined is not an object (evaluating '$commons.$promisseT') (line 34)
Controller@C:/Users/http://ift.tt/2eD1PnM

Any Ideas? :(

Aucun commentaire:

Enregistrer un commentaire