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>

代码被简化了。子指令将改变父指令的一些属性。

我想用茉莉花单元测试准确地测试这种行为:

Set enabled of parent directive true/false

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

到目前为止我所拥有的:

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();
    });


});

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

任何帮助表示赞赏。

最好的

4

0 回答 0