Unable to compile transcluded directives in unit test by Angular 1.3.0

I have a directive with transclude: true. It includes a property templatethat points to a simple HTML file with one element that contains the attribute ng-transcludeon the anchor element. An anchor element wraps the contents of a directive.

My test is as follows:

describe('foobar directive', function() {
    var $compile, $rootScope, $modal;

    beforeEach(module('collective'));
    beforeEach(module('test.templates'));

    beforeEach(inject(function(_$rootScope_, _$compile_, _$modal_) {
        $rootScope = _$rootScope_;
        $compile = _$compile_;
        $modal = _$modal_;
    }));

    it('attempts to open the modal when the wrapped element is clicked', function() {
        spyOn($modal, 'open');

        var el = $compile('<foo-bar><div id="foobar"></div></foo-bar>')($rootScope);
        $rootScope.$digest();

        el.find('#foobar').click();
        expect($modal.open).toHaveBeenCalled();
    });
});

Note that I use the ng-html2js preprocessor to load my templates into the test.templates module. It seems to work just fine for all other untranslated directives.

, $modal.open() . , . , Angular 1.2.9. Angular 1.3.0 Angular 1.3.5.

$compile :

<foo-bar class="ng-scope">
   <div id="foobar"></div>
</foo-bar>

:

<foo-bar class="ng-isolate-scope">
   <a href="#" ng-click="blah blah">
      <div id="foobar"></div>
   </a>
</foo-bar>

1.2.9, 1.3.0.

, ?

+4
2

Angular # 1.3.0 # 1.3.5 works . , , .


, ng-transclude ?

+2

@artur , , Angular 1.3.0.

, , , Angular . , , factory, , . , karma, undefined. Angular 1.2.x, , , 1.3.x !

, factory:

myModule.factory('bootbox', function() {
    return window.bootbox;
});

... :

myModule.directive('myDirective', ['$scope', 'bootbox' function($scope, bootbox) {
   //...
}]);

, window.bootbox undefined Angular 1.2.x, 1.3.x. null, , , .

+1

All Articles