mardi 29 mars 2016

unit testing directives with no templateUrl

I have several tests that do not have templateUrl assigned in the directives.

The directives are all restricted as attributes. They all have controllers and/or link functions

            return {
                restrict: 'A',
                scope: true,
                link: MyItineraryDetailsLink,
                controller: MyItineraryDetailsController
            };

Usually, with directives I have been able to mock out a directive like so

            var html = angular.element("<div directive-name></div>");
            $rootScope = $rootScope.$new();
            element = $compile(html)($rootScope);
            $rootScope.$digest(element);

            controller = element.scope();

I decided to follow the exact same approach and create a html and add a attribute on a div for a modal that I am testing

 var html = angular.element("<div modal-name></div>");

After running through the digest cycle I do not have any inner html which is somewhat expected.

element.html()    /// returns an empty string

However, this element finds classes on the div it is attached to. Like so...

  $scope.$paxSelect = $el.find('.passSelect');

How would I get an element with information to mock? Do I need it in this case?

Aucun commentaire:

Enregistrer un commentaire