0
我想使用Mocha/Chai/Sinon从我的History类中测试下面的方法,怎么样?如何使用Mocha/Chai/Sinon测试NodeJS fs?
/**
* Load the history from the history file.
* @return {this}
*/
load() {
const file = historyFilePath();
if (!fs.existsSync(file)) {
return this;
}
const json = fs.readFileSync(file, 'utf8');
const data = JSON.parse(json);
this.ary = data;
return this;
}
全班是here。
我已经注意到answer取决于rewire,但我想避免额外的依赖性和rewire也与babel不兼容。
您可以使用Sinon ['stubs'](http://sinonjs.org/releases/v2.2.0/stubs/)。 – robertklep
@robertklep我已经注意到了,我只是无法让它工作。 – maasha
如果您分享的代码无法使用,那么人们可以更轻松地为您提供帮助。 – robertklep