export { test };
const test = (str) => {
return str;
};
import { test } from './func';
describe('func', () => {
describe('func', () => {
it('should return the same string', () => {
expect(test('hello world')).to.equal('hello world');
});
});
});
我想,由于提升,test-function 是未定义的。因为如果我这样做:
const test = (str) => {
return str;
};
export { test };
测试有效。
但是,我想将我的导出保留在文件顶部以便于参考。
有什么方法可以实现吗?
我的 karma.conf.js:
const webpackConfig = require('./webpack.config');
const fileGlob = 'src/**/*.test.js';
module.exports = (config) => {
config.set({
basePath: '',
frameworks: ['mocha', 'chai'],
files: [fileGlob],
preprocessors: {
[fileGlob]: ['webpack']
},
webpack: webpackConfig,
webpackMiddleware: {noInfo: true},
reporters: ['progress', 'mocha'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['Firefox'],
singleRun: true,
concurrency: Infinity,
});
};
以及 package.json 的相关部分:
"devDependencies": {
"webpack": "^3.5.5",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.24.1",
"chai": "^4.1.1",
"mocha": "^3.5.0",
"karma": "^1.7.0",
"karma-chai": "^0.1.0",
"karma-mocha": "^1.3.0",
"karma-webpack": "^2.0.4",
},