0

Trying to unit test angular's 1 directive with template in separate file. Using jasmine and ng-html2js to stash html templates in $templateCache. On a project without SystemJS one can use:

beforeEach(module('MyStupidModule', 'templates'))

where templates - is in 'carma.conf.js'

    preprocessors: {
        'Content/templates/**/*.html' : ['ng-html2js']
    },

    ngHtml2JsPreprocessor:{
        moduleName: 'templates'
    },

and it works just fine.

But with SystemJS we now must instantiate both those modules in order to make them reachable. It is simple to mock my own module,

...
        mockAngularModule('MyStupidModule');
        // angular.mock.module('MyStupidModule');
        angular.mock.module('store', 'templates');
..

but where can I put instantiation of this 'template' module? Now it throws

Error: [$injector:modulerr] Failed to instantiate module templates due to: Error: [$injector:nomod] Module 'templates' is not available!

  • Did you ever find a solution for this? I have the exact same issue. Thanks. – snowleopard Mar 08 '17 at 20:17
  • Nope. But since we use gulp to transpile and bundle everything, I just added a task where I gather all relevant html code and make a js variable of it in a separate js file. Then put this task as a dependency for karma task and tun tests. Not much of elegancy and simplicity, but it works. – Michael Markov Mar 10 '17 at 07:16

0 Answers0