Template-Url Directive Unit Testing without Karma

谁说我不能喝 提交于 2019-12-25 11:54:40

问题


SOLUTION = Solution Plunker

I have tried manually passing the template in testing - is it even good way of doing it ? How to make it passes !!!!!!!

How to write unit test for Simple directive with template-Url without Using Karma . I have tried following after seeing examples on stack-overflow but no success.

Directive

 app.directive("crazy", function () {
    return {
        restrict: "A",
        templateUrl:"directivetemplate.html"
    };
});

Spec

   describe('Directive: crazy', function () {
   beforeEach(module('plunker'));

 beforeEach(inject(function($templateCache) {
var directiveTemplate = null;
var req = new XMLHttpRequest();
req.onload = function() {
    directiveTemplate = this.responseText;
};
req.open("get", "directivetemplate.html", false);
req.send();
$templateCache.put("directiveTemplate.html", directiveTemplate);

 }));

 it('should exist', inject(function ($rootScope, $compile) {
element = angular.element('<div crazy></div>');
element = $compile(element)($rootScope);
$rootScope.$apply();
expect(element.children().length.toBe(2));
 }));
 });

来源:https://stackoverflow.com/questions/26645708/template-url-directive-unit-testing-without-karma

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!