0
我正在使用nwb配置一個反應應用程序,我將使用像chai
和enzyme
來設置我的測試環境。我已經做了以下修改做到這一點,我創建了一個tests.webpack.js
文件:配置phantomjs使用webpack和karma nwb
import chai from 'chai';
import chaiEnzyme from 'chai-enzyme';
import chaiAsPromised from 'chai-as-promised';
import sinonChai from 'sinon-chai';
chai.use(chaiEnzyme());
chai.use(chaiAsPromised);
chai.use(sinonChai);
const context = require.context('./src', true, /\.spec\.js/);
context.keys.forEach(context);
我nwb.config.js
還修改了因果報應的配置:
const karmaChaiPlugins = require('karma-chai-plugins');
module.exports = {
type: 'react-component',
npm: {
esModules: true,
umd: {
global: 'ReactMg',
externals: {
react: 'React',
},
},
},
karma: {
testContext: 'tests.webpack.js',
plugins: [
karmaChaiPlugins,
],
frameworks: ['mocha', 'chai', 'chai-as-promised'],
},
webpack: {
compat: {
enzyme: true,
sinon: true,
},
},
};
定義index.spec.js
運行後nwb test
當我得到一個錯誤src
:
PhantomJS 2.1.1 (Linux 0.0.0) ERROR
TypeError: undefined is not a function (evaluating 'context.keys.forEach(context)')
at tests.webpack.js:73
PhantomJS 2.1.1 (Linux 0.0.0): Executed 0 of 0 ERROR (0.375 secs/0 secs)
Karma exit code was 1
的時候,我在這個問題上花費的金額過高,不知道我怎麼錯過了。謝謝@maksimr – vamsiampolu