I think your error is due to the fact that you are trying to upload your HTML file to the list of files that javascript usually accepts. I have a solution for you.
Before starting, I have karma 0.10.2, and it looks like you are at 0.8.x or lower? It works for me in 0.10.2, but I can not install 0.8.x. I will try to translate to 0.8.x, but I will not be able to verify what I am doing, so I will describe mainly from the point of view of 0.10.x. In any case, it may be easier to move to the last karma, if you can.
Config
0.10.x
External HTML parts can be loaded by karma-ng-html2js-preprocessor . This is usually used to load directly into directives via templateUrl and similar methods. In 0.10.2, you need to make sure that this package is installed (using npm), and then include the following in your karma configuration:
preprocessors: { '**/*.html' : ['ng-html2js'] }, ngHtml2JsPreprocessor: { cacheIdFromPath: function(filepath) {
This will allow you to load a module with module('inlinetemplates') , which will insert the contents of your main template file (rather than individual templates) into $templateCache .
0.8.x
So, translation for 0.8.x ... I think you need to use html2js , which is not so powerful, but included in karma in this version. You do not need to install or include it in plugins, and you cannot configure the way it is used, so you just need to
preprocessors = { '**/*.html': ['html2js'] }
The created module and the element that it inserts into $templateCache will be named using the path that you use to link to your main html template.
Javascript
0.10.x
Now you can download the corresponding module and access the contents of the main template file using
var templates = $templateCache.get('inlinetemplates')
All that remains to be done is to push your inline templates from the contents of the main template to $templateCache . This is done using the angular script directive, so we just need to compile / link the file that we downloaded using angular. You can do it very simply with
$compile(templates)(scope);
So, adding this together, you can include the following in any describe block that your templates should load.
beforeEach(module('inlinetemplates')); beforeEach(inject(function($compile, $templateCache, $rootScope) { var templatesHTML = $templateCache.get('inlinetemplates'); $compile(templatesHTML)($rootScope); }));
0.8.x
var mainTemplateLocation = 'path/used/to/refer/to/main/templates/in/karma/conf.html'; beforeEach(module(mainTemplateLocation)); beforeEach(inject(function($compile, $templateCache, $rootScope) { var templatesHTML = $templateCache.get(mainTemplateLocation); $compile(templatesHTML)($rootScope); }));
Summarizing
Again, I canβt guarantee that the 0.8.x instructions will work, especially not without configuration, but this certainly works in 0.10.x.
Karma already has the ability to push external HTML packages into your tests, all that was missing could correctly interpret your main template.