Karma babel polyfill TypeError

时间:2017-05-20 06:06:17

标签: javascript karma-runner babel redux-saga babel-polyfill

我一直在尝试在业力中使用生成器,我已经阅读了很多我需要在karma.conf.js中的测试文件之前包含polyfill文件。

这是我的karma.conf.js文件:

let webpackConfig = require('./webpack.config.js');
webpackConfig.entry = './src/index.js';

config = {

    frameworks: ['mocha', 'chai', 'sinon'],

    files: [
      './node_modules/babel-polyfill/dist/polyfill.js',
      // './node_modules/babel-polyfill/browser.js',
      './test/tests.webpack.js'
    ],

    preprocessors: {
      './src/index.js': ['webpack', 'sourcemap'],
      // './src/**/*.js': ['webpack', 'sourcemap'],
      './test/tests.webpack.js': ['webpack', 'sourcemap'],
    },

    webpack: webpackConfig,

    ...
}

但每次运行karma start时都会出现此错误:

Uncaught TypeError: Cannot read property '2' of undefined

如果我在polyfill中有files文件,则只会显示,如果我将其删除,我会收到此错误:RegeneratorRuntime is not defined

我追踪了这个错误,它来自这个(redux-saga)

var _marked = [selectedDataChanged, selectedInfoChanged, stockAppSaga].map(regeneratorRuntime.mark);

function stockAppSaga() {
    return regeneratorRuntime.wrap(function stockAppSaga$(_context3) {
        while (1) {
            switch (_context3.prev = _context3.next) {
                case 0:
                    _context3.next = 2;
                    return [
                    // takeEvery(
                    //     [actionTypes.SELECTED_TICKER_CHANGED, actionTypes.SELECTED_DATE_CHANGED],
                    //     selectedInfoChanged
                    // ),
                    (0, _effects.takeEvery)([actionTypes.SELECTED_TICKER_CHANGED, actionTypes.SELECTED_DATE_CHANGED], selectedDataChanged)];

                case 2:
                case 'end':
                    return _context3.stop();
            }
        }
    }, _marked[2], this); // this is the error line
}

我的传奇中有什么问题吗?还是巴贝尔?或者别的地方?任何帮助将不胜感激

0 个答案:

没有答案