Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 模块不是一个函数-Karma+;茉莉花&x2B;网页包+;有棱角的_Angularjs_Webpack_Karma Jasmine - Fatal编程技术网

Angularjs 模块不是一个函数-Karma+;茉莉花&x2B;网页包+;有棱角的

Angularjs 模块不是一个函数-Karma+;茉莉花&x2B;网页包+;有棱角的,angularjs,webpack,karma-jasmine,Angularjs,Webpack,Karma Jasmine,我有一个简单的angular(1.2.24)应用程序,我用Jasmine进行单元测试,我使用Karma和webpack 当我执行karma时,我在单元测试中遇到了这行代码的问题 beforeEach(module('Test')); 我得到的错误是 TypeError: module is not a function at Suite.<anonymous> (tests.webpack.js:77:14) at Object.<anonymous>

我有一个简单的angular(1.2.24)应用程序,我用Jasmine进行单元测试,我使用Karma和webpack

当我执行karma时,我在单元测试中遇到了这行代码的问题

beforeEach(module('Test'));
我得到的错误是

TypeError: module is not a function
    at Suite.<anonymous> (tests.webpack.js:77:14)
    at Object.<anonymous> (tests.webpack.js:75:48)
    at Object.<anonymous> (tests.webpack.js:94:31)
    at __webpack_require__ (tests.webpack.js:20:30)
    at webpackContext (tests.webpack.js:58:10)
    at Array.forEach (native)
    at Object.<anonymous> (tests.webpack.js:48:17)
tests.webpack.js

var webpack = require('webpack');

module.exports = function (config) {
  config.set({
    browsers: [ 'Chrome' ], //run in Chrome
    plugins: [
            'karma-jasmine',
            'karma-webpack',
            'karma-chrome-launcher'

        ],
    singleRun: true, //just run once by default
    frameworks: [ 'jasmine' ], //use the mocha test framework
    files: [
      'tests.webpack.js', //just load this file
      'TestBuild/Scripts/angular.js',
      'TestBuild/Scripts/ui-router.js'
    ],
    preprocessors: {
      'tests.webpack.js': [ 'webpack' ] //preprocess with webpack and our sourcemap loader
    },
    reporters: [ 'dots' ], //report results in this format
    webpack: { //kind of a copy of your webpack config
      devtool: 'inline-source-map', //just do inline source maps instead of the default
      module: {
        loaders: [
          { test: /js-tests\/\.js$/ , loader: 'babel-loader'}
        ]
      }
    },
    webpackServer: {
      noInfo: true //please don't spam the console when running in karma!
    }
  });
};
var context = require.context('./js-tests', true, /\.js$/); 
context.keys().forEach(context);
package.json

"main": "karma.conf.js",
  "dependencies": {
    "jasmine": "^2.5.0",
    "karma": "^1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-webpack": "^1.8.0",
    "webpack": "^1.13.2",
    "jasmine-core": "^2.5.0",
    "karma-jasmine": "^1.0.2"
  },
  "devDependencies": {
    "babel-core": "^6.14.0",
    "jasmine-core": "^2.5.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2"
  },
我已经尝试过这个解决方案,但没有效果


请让我知道如何解决这个问题。提前感谢。

看起来网页上下文中的
模块
变量与其内部使用有关


尝试在每个模块(“测试”)之前替换
与前面的
一起(角度模拟模块('Test')

对于我的案例,我在单元测试中有一个模块调用。例如,
模块('someAngularModuleName')
。根据给出答案的@Nikita_Kulazhenko,这需要转换为
angular.mock.module('someAngularModuleName')
。我希望这能让答案更加清晰。