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