我有一个文件 config.js,其中包含以下代码:
module.exports:
{
development: {
switch: false
}
}
我有另一个文件 bus.js,其中包含以下代码:
var config=require('config.js');
getBusiness:function(req,callback){
if(config.switch) {
// Do something
}else{
// Do something else
}
}
现在,我想对文件 bus.js 进行单元测试
require('mocha');
var chai = require('chai'),
expect = chai.expect,
proxyquire = require('proxyquire');
var bus = proxyquire('bus.js', {
'config':{
switch:true
}
});
describe('Unit Test', function() {
it('should stub the config.switch', function(done) {
bus.getBusiness(req, function(data) {
// It should stub the config.switch with true not false and give code coverage for if-else statmt.
});
done();
});
});
任何建议或帮助...