Jasmine无法在注入的模块中找到注入的var

时间:2017-09-04 11:55:30

标签: javascript angularjs testing jasmine karma-jasmine

我有以下情况:

目标为validate我的指令的测试类......

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是我的模块,ui-first.directivekarma.conf.js中的模板声明。

在我的指令中,我的控制器有一个inject声明......

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

$commons内,我有injector ...

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

当我运行我的测试时,Jasmine无法找到我的$commons并且测试失败...

TypeError: undefined is not an object (evaluating '$commons.$promisseT') (line 34)
Controller@C:/Users/user.user/git/gitlab/src/pop.directive.js:34:33

任何想法? :(

0 个答案:

没有答案