isolateScope() returns undefined when using templateUrl

前端 未结 5 1532
遥遥无期
遥遥无期 2021-02-07 03:41

I have a directive that I want to unittest, but I\'m running into the issue that I can\'t access my isolated scope. Here\'s the directive:

&l         


        
5条回答
  •  攒了一身酷
    2021-02-07 04:19

    You could configure karma-ng-html2js-preprocessor plugin. It will convert the HTML templates into a javascript string and put it into Angular's $templateCache service.

    After set a moduleName in the configuration you can declare the module in your tests and then all your production templates will available without need to mock them with $httpBackend everywhere.

    beforeEach(module('partials'));
    

    You can find how to setup the plugin here: http://untangled.io/how-to-unit-test-a-directive-with-templateurl/

提交回复
热议问题