setting up ng-htmljs-preprocessor karma preprocessor

允我心安 提交于 2019-12-06 01:33:08

问题


I am setting up my Karma configuration file, but I do not fully understand some of options that exist as I am not having success testing templates that have ran through the ngHtml2JsPreprocessor and have been

 $templateCached

Inside of the ngHtml2JsPreprocessor I can add a few key value properties involving paths.

 ngHtml2JsPreprocessor: {

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


     // moduleName: 'templatesCached'// 
    },

I commented out the templates for now to make sure that I am getting access to each file as module. I am loading the modules with no error. I can find the templateCached version in my dev tools.

beforeEach(module('template')); 

My Templates folder sits outside the basepath I created.

basePath: 'Scripts/',

I have it referenced inside the preprocessors object

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

Again all of my templates are now js files and cached.

I inside of my package.json I saved the files as

save-dev

"karma-chrome-launcher": "^0.2.2",
"karma-jasmine": "^0.2.2",
"karma-ng-html2js-preprocessor": "^0.2.1",

I referenced my installs in the plugins.

  plugins: [
    'karma-chrome-launcher',
    'karma-jasmine',
    'karma-sinon',
    'karma-ng-html2js-preprocessor'
],

I have all of my files loaded

files: [

  //jquery libaries
  // angular libraries
  // Scripts files
  // source app.js
  // tests folder and files
]

My tests are running off of Karma start

However, my directive is just an empty string

  element.html()  

returns ""

I have bard inject set up

bard.inject(
            "$compile",
            "$controller",
            "$rootScope",
            '$templateCache',
            "haConfig",
            "$q"
        );

Here is the inside of my beforeEach

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

I have no idea why I am getting an empty string back. I am creating the html file but, nothing is inside of it.

All I can wonder if I should have the the templatesCached files showing up in a folder on my dev tools? Also whether or not the files should be referenced inside of the files array inside karma.conf.js

Right now I have the html files referenced? I have tried the js files but that did not seem to do anything


回答1:


The problem was actually quite simple fix. I was tempted to delete it but, in case someone has a similar issue I want this to be available.

Inside the karma.conf.js I have a

   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 

When the preprocessor ran it templateCached all of my files. However, they did not end the way that I was expecting them and I could not read them. I had the module and other parts set up correctly.



来源:https://stackoverflow.com/questions/35854470/setting-up-ng-htmljs-preprocessor-karma-preprocessor

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