如何在业力中导入ES6模块

时间:2019-01-22 08:43:09

标签: javascript karma-jasmine karma-runner karma-mocha

我正在尝试对业力,摩卡咖啡和柴进行一些测试。我很困惑如何在业力中正确导入es6模块。我已经在使用karma-babel-preprocessor。谁能帮助我,非常感谢!

运行npm test时出现错误 karma error report

这是我的karma.conf.js

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['mocha', 'chai'],
    files: ['src/index.js', 'test/test_karma.js'],
    exclude: [],
    preprocessors: {
      'src/index.js': ['babel'],
      'test/test_karma.js': ['babel]
    },
    babelPreprocessor: {
      options: {
        presets: ['@babel/preset-env']
      }
    },
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['ChromeHeadless', 'Chrome'],
    singleRun: false,
    concurrency: Infinity
  })
}

这是我的index.js

const sayHello = () => {
  return 'hello karma'
}
export { sayHello }

这是我的test_karma.js

import {sayHello} from '../src/index';
import chai from 'chai';

describe('test', () => {
  it('test', () => {
    chai.assert(sayHello() === 'hello', 'say hello')
  })
})

0 个答案:

没有答案