我有一个简单的角度(1.2.24)应用程序,我在Jasmine中进行了单元测试,并使用了Karma和webpack。
当我执行业力时,我在单元测试中遇到了这行代码的问题
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)
这是我的 karma.config.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!
}
});
};
tests.webpack.js
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"
},
我已经在karma + jasmine + webpack: module is not a function尝试了解决方案,但它没有帮助。
请告诉我如何解决这个问题。提前谢谢。
答案 0 :(得分:5)
看起来webpack上下文中的@RunWith(SpringRunner.class)
@ContextConfiguration(classes = RealDbDAOTests.class)
@Transactional
@Rollback
public class DaoTests {
....
}
变量与其内部使用有关。
尝试将module
替换为beforeEach(module('Test'));