configuring karma ng-html2js preprocessor to find my templates in inside a directory

Subtubes picture Subtubes · Apr 3, 2014 · Viewed 7.1k times · Source

The problem I am having is that I want to make the templateUrl: "partials/my-directive.html"

but currently I have to make it templateUrl: "app/partials/my-directive.html in order for it to be loaded by Karma.

this is my folder structure (basically yeoman folder structure)

app
    partials
        my-directive.template.html
    directives
        my-directive.js
    app.js

karma.conf.js

here is the directive code

   angular.module("exampleApp")
    .directive("adminMod", function () {
        return {
            restrict: "E",
            templateUrl: "app/partials/admin-mod.html",
            scope: {
                props: "="
            }
        }
    });

heres the unit test part

     beforeEach(module("app/partials/admin-mod.html"));

heres the karma.conf.js

      files: [
        'app/bower_components/jquery/jquery.js',
        'app/bower_components/angular/angular.js',
        'app/partials/*.html'
    ],

    preprocessors: {
        'app/partials/*.html': 'ng-html2js'
    },

    ngHtml2JsPreprocessor: {

       //prependPrefix: ???? what do I make this 
    },

I'd like to make the url relative to the app folder not my karma.conf.file I think I have exhausted every combination of paths can someone explain what and how this is supposed to work with a Yeoman angular generator file structure

Answer

Subtubes picture Subtubes · Apr 3, 2014

The problem was that I was trying to use

ngHtml2JsPreprocessor: {

   prependPrefix: ???? what do I make this 
},

but what I should really have been using is

ngHtml2JsPreprocessor: {
    stripPrefix: 'app/',
},

I can then just keep the route relative to the app/ folder and require the template as a model like this in the unit tests

beforeEach(module("partials/admin-mod.html"));

which is the same path in my directive

templateUrl: "partials/admin-mod.html",