1

I am just starting to set up some tests with Karma. I some tests working with jdDom, but did not like how it was configuring. However, I am not sure how to point to the js files correctly. As I am getting this error

 Error: [$injector:modulerr] Failed to instantiate module ha.module.utility due to:
    Error: [$injector:nomod] Module 'ha.module.utility' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

I started a file with jsdom that required the core modules

require('../../../src/modules/core/module.core.built.js'); require('../../../src/modules/utility/module.utility.built.js');

These scripts are where my modules reside. I am not sure where to put them in the karma file. Or if this is even the issue . Here is my karma file below. I removed the comments that come with karma init so it could be quicker to read on this post.

config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: 'Scripts/',

frameworks: ['jasmine'],


// list of files / patterns to load in the browser
files: [
    'jquery /jquery libraries ',
    '../node_modules/angular/angular.js',
    '../node_modules/angular-mocks/angular-mocks.js',
    'test2/*.js',
    'tests/**/*.js'

],
exclude: [
    'tests/old/**',
    'tests/**/*.setup.js'
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
    '../Templates/**/*.html' : ['ng-html2js']
},

ngHtml2JsPreprocessor: {
        // setting this option will create only a single module that contains templates
        // from all the files, so you can load them all with  angular.mock.module('foo')

        //stripPrefix: "Templates/",
        //prependPrefix: "Templates/",
        moduleName: 'templates'
    },

// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],


port: 9876,

colors: true,


logLevel: config.LOG_INFO,


autoWatch: true,



browsers: ['Chrome'],

singleRun: true,

concurrency: Infinity 

Basically I need these tests to find the modules.

1 Answer 1

3

Your modules' directives, controllers, and all other required files should be uploaded into your list of "files," like this:

files: [
    '../node_modules/angular/angular.js',
    '../node_modules/angular-mocks/angular-mocks.js',
    '../../../src/modules/core/module.core.built.js',
    '../../../src/modules/utility/module.utility.built.js',
    'test2/*.js',
    'tests/**/*.js'

],
Sign up to request clarification or add additional context in comments.

3 Comments

Ok that makes sense to put it in files. Ideally I would put those before my tests correct?
Correct. For my Karma tests, I have all of my .js dependencies first, then my controller and directives, then the main app.module.js, then bringing up the rear are the tests.
Is this issue also feasible with ng2Html preprocessor? I re-occured this error when I started the preprocessor and pointed to the Templates folder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.