加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 设置ng-htmljs-preprocessor karma预处理器

发布时间:2020-12-17 06:58:53 所属栏目:安全 来源:网络整理
导读:我正在设置我的Karma配置文件,但我不完全理解存在的一些选项,因为我没有成功测试已经通过ng Html2JsPreprocessor运行的模板 $templateCached 在ngHtml2JsPreprocessor中,我可以添加一些涉及路径的键值属性. ngHtml2JsPreprocessor: { stripPrefix: ".*/Went
我正在设置我的Karma配置文件,但我不完全理解存在的一些选项,因为我没有成功测试已经通过ng Html2JsPreprocessor运行的模板

$templateCached

在ngHtml2JsPreprocessor中,我可以添加一些涉及路径的键值属性.

ngHtml2JsPreprocessor: {

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

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

beforeEach(module('template'));

我的Templates文件夹位于我创建的基道之外.

basePath: 'Scripts/',

我在预处理器对象中引用它

preprocessors: {
    '../Templates/**/*.html' : ['ng-html2js']
},

我的所有模板现在都是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
]

我的测试开始于Karma

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

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);

我不知道为什么我要回一个空字符串.我正在创建html文件,但内部没有任何内容.

所有我都想知道我是否应该在我的开发工具的文件夹中显示templatesCached文件?另外,是否应该在karma.conf.js内的files数组中引用文件

现在我引用了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

当预处理器运行时,templateCached我的所有文件.但是,它们没有像我期待的那样结束,我无法阅读它们.我正确设置了模块和其他部件.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读