AngularJS and Karma cannot call the 'module' method from undefined

I start karma inside AngularJs yeoman substrates . The error "Unable to call the method" module "from undefined" is located in the gruntfile.js file created by yoman on the first linemodule.exports = function (grunt) { ...

Value of karma.conf.js

module.exports = function(config) {
config.set({

// base path, that will be used to resolve files and exclude
basePath: '',

frameworks: ['jasmine'],


// list of files / patterns to load in the browser
files: [
    '**/*.js',
    'app/bower_components/**/*.js'
],

exclude: [ ],

reporters: ['progress'],

// web server port
port: 9876,

colors: true,

logLevel: config.LOG_INFO,

autoWatch: true,

browsers: ['Chrome'],

captureTimeout: 60000,

singleRun: false
});
};

angular.js includes inside bower_components.

+4
source share
2 answers

The problem is caused by the announcement files. Since you are loading **/*.js, your subsequent inclusion of bower components is not necessary (it is already loaded with the first call).

, , . , karma.conf.js:

files: [
    // Required libraries
    'assets/bower_components/jquery/dist/jquery.js',
    'assets/bower_components/angular/angular.js',
    'assets/bower_components/angular-resource/angular-resource.js',
    'assets/bower_components/ng-table/ng-table.js',

    // App under test
    'assets/javascripts/**/!(*.spec).js',

    // Mocks
    'test/js/lib/angular/angular-mocks.js',

    // Templates
    'assets/javascripts/angular/**/*.html',

    // Finally... tests
    'assets/javascripts/**/*.spec.js',
    'test/js/unit**/*.js'
],

. JS, Angular mocking library. , , .

!(*.spec).js, (, ) .

+4

app/bower_components/**/*.js , , .js (, -), ,

angular ,

app/bower_components/angular/angular.js,
app/bower_components/angular-mocks/angular-mocks.js

angular-mocks, , - module, inject...

+1

Source: https://habr.com/ru/post/1530245/


All Articles