业力角度模板找不到网址



我在用业力测试角度指令时遇到了一些问题,问题是当来自模板URL时,永远不会翻译它。

这是我的业力.js

'use strict';
var wiredep = require('wiredep');
var bowerFiles = wiredep().js;
var appFiles = [
  'src/modules/**/*-module.js',
  'src/modules/**/**/*.js',
  { pattern: 'src/modules/**/*.mol', watched: true, served: true, included: false },
  'src/modules/**/**/templates/*.html',
  {
    pattern: '../src/assets/images/*.*',
    watched: false,
    included: false,
    served: true
  },
  'src/modules/**/**/templates/*.html'
];
module.exports = function (config) {
  config.set({
    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',
    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: [
      'mocha',
      'chai',
      'sinon-chai'
    ],
    junitReporter: {
      outputFile: '../reports/test-results/test-results.xml'
    },
    coverageReporter: {
      dir: 'reports/test-coverage/',
      subdir: function (browser) {
        // normalization process to keep a consistent browser name across different OS
        return browser.toLowerCase().split(/[ /-]/)[0];
      },
      check: {
        global: {
          statements: 10,
          branches: 1,
          functions: 10,
          lines: 10
        },
        each: {
          statements: 0,
          branches: 0,
          functions: 0,
          lines: 0
        }
      },
      reporters: [
        { type: 'html', file: 'coverage.html' },
        { type: 'cobertura', file: 'coverage.xml' },
        { type: 'json' },
        { type: 'text-summary' }
      ]
    },
    reporters: ['junit', 'dots', 'coverage'],
    // list of files / patterns to load in the browser
    files: [].concat(bowerFiles, appFiles),
    // list of files to exclude
    exclude: [],
    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
      'src/modules/**/**/!(*.test).js': 'coverage',
      'src/modules/**/**/templates/*.html': ['ng-html2js']
    },
    ngHtml2JsPreprocessor: {
      stripPrefix: 'src/',
      moduleName: 'templates'
    },
    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    // web server port
    port: 9876,
    // enable / disable colors in the output (reporters and logs)
    colors: true,
    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,
    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,
    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Chrome'],
    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,
    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity
  });
};

而测试...

'use strict';
describe('dra-header-directive', function () {
  var compile;
  var rootScope;
  var templateCache;
  beforeEach(module('dd'));
  beforeEach(module('templates'));
  beforeEach(inject(function ($compile, $rootScope, $templateCache) {
    compile = $compile;
    rootScope = $rootScope;
    templateCache = $templateCache;
  }));
  it('Replace the element with the appropiate element', function () {
    var scope = rootScope.$new();
    var el = angular.element('<testing></testing><dra-header></dra-header><input-bar></input-bar>');
    var element = compile(el)(scope);
    scope.$digest();
    console.log(element);
  });
});

第一个标签被翻译是因为没有定义为模板URL,但其他标签没有。

如果我得到带有$templateCache的模板,我可以阅读内容,所以我 ng-html2js 正在做它的工作。 有什么想法吗?感谢您的帮助!

它解决了,我更改了每个模块之前以避免导入不必要的模块依赖项,看起来有一些东西正在修改我的 rootScope,我只是加载了具有指令的模块,现在工作正常

'use strict';
describe('dra-header-directive', function () {
  var compile;
  var scope;
  var templateCache;
  beforeEach(module('dra.components.DRAHeaderModule'));
  beforeEach(function () {
    module('templates');
  });
  beforeEach(inject(function ($compile, $rootScope, $templateCache) {
    compile = $compile;
    templateCache = $templateCache;
    scope = $rootScope.$new();
  }));
  it('Replace the element with the appropiate element', function () {
    var el = angular.element('<dra-header></dra-header>');
    compile(el)(scope);
    scope.$digest();
    expect(el.find('div')[0]).to.not.be.undefined();
  });
});

最新更新