我正在尝试对我的代码进行单元测试。我需要测试一个有相对url的api调用。我试图使用supertest进行api模拟。
以下是我的测试代码片段:
const express = require('express');
const app = express();
const supertest = require('supertest');
app.use(express.bodyParser());
it('should get required details', (done) => {
supertest(app)
.get('/home/api/getdetails')
.expect(200, { response: { foo: 'bar', done);
const expectedActions = [{ type: 'DETAILS',
payload: { foo: 'bar' } }];
const store = mockStore({}, expectedActions);
const func = getDetails();
// eslint-disable-next-line
console.log("func"+func);
const dispatch = sinon.spy();
func(dispatch);
expect(store.getActions()).
to.deep.equal(expectedActions);
});
这是我的webpack.config.js
var path = require('path');
var env = require('./env');
// List of allowed environments
var allowedEnvs = ['env1', 'env2', 'env3', 'env4', 'env5', 'env6', 'env7', 'env7'];
// Get available configurations
var configs = {
env0: require(path.join(__dirname, 'cfg/env0')),
env1: require(path.join(__dirname, 'cfg/env1')),
env2: require(path.join(__dirname, 'cfg/env2')),
env3: require(path.join(__dirname, 'cfg/env3')),
env4: require(path.join(__dirname, 'cfg/env4')),
env5: require(path.join(__dirname, 'cfg/env5')),
env6: require(path.join(__dirname, 'cfg/env6')),
env7: require(path.join(__dirname, 'cfg/env7')),
env8: require(path.join(__dirname, 'cfg/env8')),
};
/**
* Get an allowed environment
* @param {String} env
* @return {String}
*/
function getValidEnv(env) {
var isValid = env && env.length > 0 && allowedEnvs.indexOf(env) !== -1;
return isValid ? env : 'dev';
}
/**
* Build the webpack configuration
* @param {String} env Environment to use
* @return {Object} Webpack config
*/
function buildConfig(env) {
var usedEnv = getValidEnv(env);
return configs[usedEnv];
}
module.exports = buildConfig(env);
到处都是,只是通过添加,
node:{
fs: 'empty',
}
会解决问题。但是,这个问题并没有解决。 有人可以帮帮我吗?
谢谢你, Aswini J