【问题标题】:Testing react and redux with karma and mocha使用 karma 和 mocha 测试 react 和 redux
【发布时间】:2016-06-13 16:48:04
【问题描述】:

我已经开始使用 React 和 Redux,我想使用带有 Mocha 和 PhantomJS2 的 Karma 来编写测试。我在这里使用来源作为基础:https://github.com/reactjs/redux/tree/master/examples/counter。我基本上想使用 Phantom 在 Karma 中运行测试,而不是使用节点和“npm 测试”。

我已经设置并安装了 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
    })
}

【问题讨论】:

    标签: unit-testing reactjs mocha.js karma-runner redux


    【解决方案1】:

    对于 react-boilerplate,我们有准确的设置 - 看看我们的 karma.conf.js 和实现 Karma 的 PR,如果有帮助,请告诉我!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-13
      • 1970-01-01
      • 1970-01-01
      • 2017-01-16
      • 1970-01-01
      • 2016-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多