我的单元测试用例失败,我收到一条错误消息
'TypeError:无法读取未定义的属性'url'。
具有 url 属性的配置文件似乎有问题。请有人帮助我。
// Employee.js
const config = require('../../config/config');
const api = require('./api');
class Employee {
constructor() {
}
getEmp() {
return api.post({
url: config.url,
});
}
}
module.exports = Employee;
//Employee.test.js
const chai = require('chai');
const sinon = require('sinon');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised).should();
const proxyquire = require('proxyquire');
describe('Test', function () {
let myController;
let sandbox;
beforeEach(() => {
sandbox = sinon.sandbox.create();
myController = proxyquire('../src/Employee.js', { 'config': {}, 'api': {} });
});
afterEach(function afterEach() {
sandbox.restore();
});
it('my Test', (done) => {
let controller = new myController();
controller.getEmp()
.then(response => {
console.log('its me ' + response);
done();
});
});
});