尝试运行用ES6编写的最简单的茉莉花测试:
单位/ page.test.js
describe("test", function () {
it("test", function () {
[].find();
// Object.assign(); // this fails as well
});
});
我收到以下错误:
TypeError: undefined is not a constructor (evaluating 'Object.assign()') in page.test.js (line 145)
看起来它不知道新的ES6方法。我觉得polyfill是缺失的部分。
的package.json
{
"name": "tests",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "karma start"
},
"author": "eagor",
"devDependencies": {
"babel-core": "^6.21.0",
"babel-loader": "^6.2.10",
"babel-preset-latest": "^6.16.0",
"jasmine": "^2.5.3",
"jasmine-core": "^2.5.2",
"karma": "^1.4.0",
"karma-babel-polyfill": "0.0.5",
"karma-babel-preprocessor": "^6.0.1",
"karma-jasmine": "^1.1.0",
"karma-phantomjs-launcher": "^1.0.2",
"karma-webpack": "^2.0.1",
"webpack": "^1.14.0"
}
}
karma.conf.js
module.exports = function(config) {
config.set({
browsers: ['PhantomJS'],
basePath: "./Unit",
files: [
{ pattern: '**/*.test.js', watched: false }
],
frameworks: ['jasmine'],
preprocessors: {
'**/*.test.js': ['webpack']
},
webpack: {
module: {
loaders: [
{ test: /\.js/, exclude: /node_modules/, loader: 'babel-loader' }
]
},
// watch: true
},
webpackServer: {
noInfo: true
}
});
};
答案 0 :(得分:0)
我在这里遇到了同样的问题。我试图在Webpack的repo but it got shut down with no further notice上打开一个问题。我设法通过添加.babelrc
来解决问题,并且它在昨天工作。今晚,我没有碰到这个项目,我的测试不再适用了。 Karma和Webpack之间可能存在一些问题。