0

私はカルマで角度指示をテストするときにいくつかの問題があります。問題は、templateUrlから来たときに翻訳が行われないことです。ここ カルマ角度templateUrlが見つかりません

は、「私の最初のタグが原因templateUrlとして定義されていないに変換され

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

}); 

karma.conf.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 
    }); 
}; 

とテスト

...が、他のドンでありますt。

テンプレートを$ templateCacheで取得した場合、そのコンテンツを読むことができるので、ng-html2jsがその仕事をしていると思います。何か案は? 助けてくれてありがとう!

+0

私はこのテスト 'describe.only'のみを実行するといくつかのアップデートがあります。 – Didvae

答えて

0

その私の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(); 
    }); 

}); 
の作品、私はunnecesaryモジュールの依存関係をインポートしないように、各モジュールの前に変更され、解決しました
関連する問題