I'm trying to do some testing with karma, mocha and chai. I'm confused how to import es6 module correctly in karma. I am already use karma-babel-preprocessor
. Could anyone help me, thanks a lot!
Here is the error when run npm test
Here is my 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
})
}
Here is my index.js
const sayHello = () => {
return 'hello karma'
}
export { sayHello }
Here is my test_karma.js
import {sayHello} from '../src/index';
import chai from 'chai';
describe('test', () => {
it('test', () => {
chai.assert(sayHello() === 'hello', 'say hello')
})
})