我已经开始使用React和Redux了,我想用Mocha和PhantomJS2的Karma来为它写测试。我使用这里的源代码作为基础:https://github.com/reactjs/redux/tree/master/examples/counter。我基本上想在Karma中使用Phantom来运行测试,而不是使用node和"npm test“。
我已经设置并安装了karma所需的包:
package.json
"scripts": {
"test:karma": "karma start",
},
"karma": "^0.13.21",
"karma-babel-preprocessor": "^6.0.1",
"karma-mocha": "^0.2.2",
"karma-phantomjs2-launcher": "^0.5.0",
"phantomjs2": "^2.2.0",我试图找出如何构建我的karma.config.js,但我似乎没有让我的测试运行,这就是我需要帮助的地方。
karma.config.js
module.exports = function(config) {
process.env.PHANTOMJS_BIN = './node_modules/phantomjs2/lib/phantom/bin';
config.set({
basePath: './',
frameworks: ['mocha'],
plugins: [ 'karma-mocha', 'karma-phantomjs2-launcher', 'karma-babel-preprocessor' ],
files: [
"components/Counter.js",
"test/components/Counter.spec.js"
],
preprocessors: {
"components/Counter.js": ["babel"],
"test/components/Counter.spec.js": ["babel"]
},
babelPreprocessor: {
options: {
"presets": ["es2015", "react"],
}
},
reporters: ['progress'],
browsers: ['PhantomJS2'],
port: 9099,
runnerPort: 9100,
urlRoot: '/',
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
singleRun: false,
concurrency: Infinity
})
}发布于 2016-03-01 18:40:13
对于react-boilerplate,我们有确切的设置--看看我们的karma.conf.js和实现Karma的PR,让我知道这是否有帮助!
https://stackoverflow.com/questions/35720015
复制相似问题