javascript - Could not load the template HTML file in Karma tests for a Angular directive -


Despite issues similar to some people (like [here] [1] or [there] [2]), I did I did not succeed in testing my instructions in my conjunction (1.2.25) application.

This is my project structure:

  myapp + - src / main / java / resources / meta-INF / resource / workflow / instructions. + - Instructions. Js | + - * .html (all templates) + - src / test / javascript + - karma.conf.js + - spec / instructions + - text-input. Spec.js  

(yes , Is not a good structure, but my angular application is stuck in the Java project)

My action configuration:

  // Karma Configuration Module Exports = function (configuration) {Config.set ({... // base path, which will be used to resolve the file and exclude the path of paths: '', // to use the test framework (Chamelie / Moca / kinet / ...) Frameworks: ['Chameli'], // To load the list of files / patterns in browser files: [// Third party dependency: jQuery, Connor, angular module, Connor socks '../../main/resources/META-INF/resources/Workflow / Bower_component / ...', // May Instructions '../../main/resources/META-INF/resources/workflow/directives/*.html', '../../main/resources/ js' META-INF / Resources / Workflow / Instructions / *., // My application '../../main/resources/META-INF/resources/workflow/scripts/*.js',' ../../main/resources/META-INF/ source / Workflow / app / ** / * .js', // my test files' speck / directives / * .js'], // not to exclude the list of files / patterns: [], // web server Port port: 8888, Browser: ['Chrome'], // plug-in to enable // plugin: ['Karma-ng-HT-2-J S-preprocessor ',' Karma-chrome-launcher ',' Karma-Jasmin '], preprocessor: {' ../ .. /main/resources/META-INF/resources/workflow/directives/*.html ': [ 'Ng-html2js']}, ngHtml2JsPreprocessor: {// Not sure what is kept here ...}, ...}); };  

My test:

  Description ('instructions: text-input', function () {var element, scope; first (each module ('myApp ');) First (inject (function ($ root scope, $ compilation) {scope = $ rootsecope. $ New (); element =' & lt; div my-input-text data-label = "foo" data-model = "Bar" & gt; lieutenant; $ div /, function () {hope (element.text ()) ToBe ('Foo');});});});  

And the manual itself:

  var myDirs = angular.module ('my-directives', []); // text input myDirs.directive ('myInputText', function () {return} {replace: true, templateUrl: 'directives / text-input.html', scope: {label: '=', readOnly: '=', Code: '=', model: '='}};});  

While running ( grunt karma ), I get the error:

  Chrome 31.0.1650 (Windows 7) Instructions: Text-input Basic tests should be editable FAILED error: Unexpected request: Get directions / text-input: no more request  

I still do not get wrong My preprocessor I tried a lot of configuration in ngHtml2JsPreprocessor , but there is an error The only one I have seen in the debug log that the pre processor is working on my template HTML files:

  debug [preprocessor.html2js]: "d: / dev / my-app / src / Main / resources / META-INF / resource / workflow / instructions / text input.html ".  

Thanks.

I finally found a solution in my karma.conf.js I have set a module-name , such as:

  ngHtml2JsPreprocessor: {moduleName: 'my-directives'},  

Then, in my Jasmine test, I add it:

First of all (module 'myApp'); BeforeEach (module ('my-instructions'));

Another solution is to set the HTML code as a module directly to karma.conf.js :

  The first one is to change (module ('instructions / text input.html'));  

But not a good solution because I have directive / * html ...


Comments