2

I have setup karma as my unit test framework. But it doesn't compile below code:

let {btnData} = this.props
let buttons = []
for (let btn of btnData) {
  btn = {...btnCategories[btn.type], ...btn}
  buttons.push(btn)
}

I got below error on the line of for loop. Why doesn't it recognise for...of statement?

Can't find variable: Symbol

Below is my karma config file. My project includes webpack, reactjs and use karma, mocha, chai, enzyme as test libraries.

var path = require('path')
module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['mocha', 'chai'],
    files: [
      '../test/**/*.js'
    ],

    preprocessors: {
      // add webpack as preprocessor
      '../src/**/*.js': ['webpack', 'sourcemap'],
      '../test/**/*.js': ['webpack', 'sourcemap'],
      '../src/**/*.less': ['webpack', 'sourcemap']
    },
    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$/,
            loader: 'babel',
            exclude: /node_modules/,
            query: {
              presets: ['airbnb']
            }
          },
          {
            test: /\.json$/,
            loader: 'json',
          },{
            test: /\.less$/,
            loader: "style!css!less",
          },
        ]
      },
      externals: {
        'react/lib/ExecutionEnvironment': true,
        'react/lib/ReactContext': true,
        'react/addons': true
      },
      resolve: {
        alias: {
          app: path.join(__dirname, '../src/js')
        }
      }
    },

    webpackServer: {
      noInfo: true //please don't spam the console when running in karma!
    },

    plugins: [
      'karma-webpack',
      'karma-jasmine',
      'karma-sourcemap-loader',
      'karma-chrome-launcher',
      'karma-phantomjs-launcher',
      'karma-mocha',
      'karma-chai',
      'karma-mocha-reporter'
    ],


    babelPreprocessor: {
      options: {
        presets: ['airbnb']
      }
    },
    reporters: ['mocha'],

    // reporter options
    mochaReporter: {
      colors: {
        success: 'blue',
        info: 'bgGreen',
        warning: 'cyan',
        error: 'red'
      },
      symbols: {
        success: '+',
        info: '#',
        warning: '!',
        error: 'x'
      }
    },
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
  })
};
Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523

0 Answers0