Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 设置ng htmljs预处理器karma预处理器_Angularjs_Unit Testing_Karma Runner_Ng Html2js - Fatal编程技术网

Angularjs 设置ng htmljs预处理器karma预处理器

Angularjs 设置ng htmljs预处理器karma预处理器,angularjs,unit-testing,karma-runner,ng-html2js,Angularjs,Unit Testing,Karma Runner,Ng Html2js,我正在设置我的Karma配置文件,但我不完全了解存在的一些选项,因为我没有成功地测试通过NGHTML2JS预处理器运行并已成功运行的模板 $templateCached 在NGHTML2JS预处理器内部,我可以添加一些涉及路径的键值属性 ngHtml2JsPreprocessor: { stripPrefix: ".*/Went all the way back to the root of my application/", // moduleName: 't

我正在设置我的Karma配置文件,但我不完全了解存在的一些选项,因为我没有成功地测试通过NGHTML2JS预处理器运行并已成功运行的模板

 $templateCached
在NGHTML2JS预处理器内部,我可以添加一些涉及路径的键值属性

 ngHtml2JsPreprocessor: {

      stripPrefix: ".*/Went all the way back to the root of my application/",


     // moduleName: 'templatesCached'// 
    },
我现在注释掉了模板,以确保我可以作为模块访问每个文件。我正在加载模块,没有错误。我可以在我的开发工具中找到templateCached版本

beforeEach(module('template')); 
我的Templates文件夹位于我创建的basepath之外

basePath: 'Scripts/',
我在预处理器对象中引用了它

同样,我所有的模板现在都是js文件并被缓存

在我的package.json中,我将文件保存为

save-dev

"karma-chrome-launcher": "^0.2.2",
"karma-jasmine": "^0.2.2",
"karma-ng-html2js-preprocessor": "^0.2.1",
我在插件中引用了我的安装

  plugins: [
    'karma-chrome-launcher',
    'karma-jasmine',
    'karma-sinon',
    'karma-ng-html2js-preprocessor'
],
我已经加载了我所有的文件

files: [

  //jquery libaries
  // angular libraries
  // Scripts files
  // source app.js
  // tests folder and files
]
我的测试正在运行的因果报应开始

然而,我的指令只是一个空字符串

  element.html()  
返回“”

我已经给巴德注射了

bard.inject(
            "$compile",
            "$controller",
            "$rootScope",
            '$templateCache',
            "haConfig",
            "$q"
        );
这是我的生日礼物

 bard.mockService(haConfig, {
            getTemplateUrl: '/tst!'
        });

        //bard.mockService(haConfig, {});
        console.log('ha config2', haConfig.getTemplateUrl());

        var html = angular.element("<div explore-hero></div>");

        console.log('htl',haConfig.getTemplateUrl());

        scope = $rootScope.$new();
        //templateCache
        element = $compile(html)(scope);
        //console.log(haConfig.getTemplateUrl(html));
        scope.$digest(element);
        console.log('missing text',haConfig.getTemplateUrl(html));

        controller = element.scope();

        console.log("element", element);
bard.mockService(haConfig{
getTemplateUrl:'/tst!'
});
//bard.mockService(haConfig,{});
log('ha config2',haConfig.getTemplateUrl());
var html=angular.element(“”);
log('htl',haConfig.getTemplateUrl());
scope=$rootScope.$new();
//模板缓存
元素=$compile(html)(范围);
//log(haConfig.getTemplateUrl(html));
范围。$摘要(要素);
log('missing text',haConfig.getTemplateUrl(html));
controller=element.scope();
console.log(“元素”,元素);
我不知道为什么我得到一个空字符串回来。我正在创建html文件,但里面什么都没有

我唯一想知道的是,我是否应该将模板压缩文件显示在我的开发工具的文件夹中?此外,文件是否应在karma.conf.js内的文件数组中引用


现在我引用了html文件?我尝试了js文件,但似乎没有做任何事情

问题其实很简单。我试图删除它,但如果有人有类似的问题,我希望这是可用的

在karma.conf.js中,我有一个

   stripPrefix: 'rootDirectory'   // was already in place

   stripSuffix: '.js.html' // I had to make a strip on the templatesCached 

   prependSuffix: '.html'  // this is what I was searching for 

当预处理器运行时,它以模板缓存了我的所有文件。然而,它们并没有像我期待的那样结束,我无法阅读它们。我已正确设置了模块和其他部件

您是否将html文件包含在
文件:[]
中?另外,在每个块之前,尝试在另一个
块中编译元素。我最终解决了这个问题,结果很简单
   stripPrefix: 'rootDirectory'   // was already in place

   stripSuffix: '.js.html' // I had to make a strip on the templatesCached 

   prependSuffix: '.html'  // this is what I was searching for