2016-12-18 80 views
0

我正在使用nwb配置一個反應應用程序,我將使用像chaienzyme來設置我的測試環境。我已經做了以下修改做到這一點,我創建了一個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 

回答