使用Jasmine 2进行单元测试属性angular指令

时间:2016-11-30 10:32:27

标签: angularjs angularjs-directive jasmine2.0

我有一个属性指令,将与另一个父指令一起使用:

function childDirective(/*injection*/) {
  return {
    restrict: 'A',
    replace: true,
    transclude: false,
    require: 'parentDirective',
    link: link
  };
  function link(parentScoep, element, attrs) {/*directive logic*/}
}

它在父指令中使用:

<parent-directive child-diretive></parent-directive>

代码简化了。 child指令将更改父指令的某些属性。

我想用茉莉花单元测试来测试这种行为:

Set enabled of parent directive true/false

我有点迷失在哪里开始。我从未测试过这样的设置。

到目前为止我所拥有的:

&#13;
&#13;
describe('childDirective', function () {
    var compile;
    var rootScope;
    var element;

    angular.mock.module('myProject', function ($compileProvider, $provide) {
        $compileProvider.directive('parentDirective', function () {
            return {
                priority: 100,
                terminal: true,
                restrict: 'E',
                template: '<div child-directive</div>'
            };
        });
        
    });

    angular.mock.inject(['', '$compile', '$rootScope', function ($compile, $rootScope) {
        rootScope = $rootScope;
        compile = $compile;
    }]);

    it('test', function () {
        expect(true).toBeTruthy();
    });


});
&#13;
&#13;
&#13;

我正在努力开始,为实际的单元测试准备设置。测试这种设置的最佳方法是什么

感谢任何帮助。

最佳

0 个答案:

没有答案
相关问题