모카/차이/사이먼을 사용하여 내 기록 수업에서 아래의 방법을 테스트하고 싶습니다. 어떻게해야합니까?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에 주목했지만 여분의 의존성을 피하고 재 와이어도 바벨과 호환되지 않습니다.
Sinon ['stubs'] (http://sinonjs.org/releases/v2.2.0/stubs/)을 사용할 수 있습니다. – robertklep
@robertklep 나는 그것을 깨달았지만, 나는 그것을 작동시킬 수 없다. – maasha
작동하지 않는 코드를 공유하면 사람들이 쉽게 도움을받을 수 있습니다. – robertklep