0

I have an attribute directive that will be used with another parent directive:

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

And it is used in parent directive:

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

The code is simplified. The child directive will change some attributes of parent directive.

I would like to test exactly this behavior with jasmine unit test:

Set enabled of parent directive true/false

I am kind of lost where to start. I have never tested such a setup.

What I have so far now:

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


});

I am struggling to get started, to prepare the setup for the actual unit tests. What is the best way to test such a setup

Any help is appreciated.

Best

amol01
  • 1,823
  • 4
  • 21
  • 35
  • Test it with parent directive. Look here, how angular developers test ng-change (require ng-model): https://github.com/angular/angular.js/blob/07849779ba365f371a8caa3b58e23f677cfdc5ad/test/ng/directive/ngChangeSpec – Petr Averyanov Nov 30 '16 at 10:52
  • If possible, I would test it without touching the parent directive. Your link will result in not found page. – amol01 Nov 30 '16 at 12:10

0 Answers0