karma-ng-html2js-preprocessor
karma-ng-html2js-preprocessor copied to clipboard
Usage instructions unclear
It would be great to have a set of instructions outlining the exact steps needed to configure directive testing with external templates when using the "standard" AngularJS building tools/scaffolding provided via yo angular and yo angular:directive ....
Using that scaffolding, and modifying the directive to use templateUrl instead of inline HTML strings, I followed the guidelines found here and in the ng-directive-testing, including all modifications in karma.conf.js and inclusion of the template path as a module in the directive test spec js file, but testing still does not work for me. I get the following error, regardless:
Error: No module: views/whateverTemplate.html
No combination of modifying stripPrefix and module names has allowed Karma/Angular to find the 'module' of my external template. Furthermore, there is not enough information here or in the aforementioned repo to even know where to look to debug this, verify that the module, or the requisite .html.js files, were created, etc.
(This is on GNU/Linux, using AngularJS 1.0.8, Karma 0.10.4 and everything else that gets installed by default via the current stable version of yeoman/yo (1.0.4).)
I have spent a long time getting this to work. In the end it was all down the stripPrefix. Go into Chrome Developer tools and look at the compiled templates and see what prefix has been appended. This must match the template URL you have specified in the directive.
Thanks spwizard, for me the solution was in fixing files: [...], which I had completely looked over. Referenced here.
This will remain unclear to someone does a full test example for the angular generator using external template url. In the example you refer to, there is just a "todo" notification about doing it with url in "future". Would be really appreciated if someone makes a full example.
Agreed. I had a very frustrating 1.5hrs to arrive at a working config. So, I'm all for improving the docs :)
The biggest issue I ran into was not including the plugin in my config file under plugins: []. The Karma docs are vague on this, stating that all npm packages prefixed with karma-* are preloaded, however, it does not specify that (apparently?) no plugins are loaded if you provide a plugins: [] option in your config.
Credit to this SO for that solve.
I started a branch to improve the docs for the issues I had, it'd be great if we could all direct our energy into that PR: https://github.com/karma-runner/karma-ng-html2js-preprocessor/pull/60
@spwizard , Thanks.
Had the same issue today.
+1 An example would be really appreciated.