10
의 기능을 스텁. 그러나 two()
을 스터브해야합니다. 유닛 테스트를 수행하면서 two()
이 실제 코드에서 실행될 때 발생하는 부작용을 제거해야합니다.내가 단위 테스트에 다음과 같은 단순화 된 모듈을 원하는 proxyquired 객체
it.only('stubbing functions on the "proxyquired" object under test', function(done) {
const loggerStub = {
create:() => {
return { log: (msg) => { console.log('fake logger: ', msg); } };
}
};
let tester = proxyquire('../tester', { 'logplease': loggerStub });
let stub2 = sinon.stub(
tester,
'two',
() => {
console.log('called fake stub of two()');
}
);
tester.one();
console.log('call count 2: ', stub2.callCount);
done();
});
출력 내가 얻을 :
fake logger: called real one()
fake logger: called real two()
call count 2: 0
출력 내가 기대 :
fake logger: called real one()
called fake stub of two()
call count 2: 1
왜 스텁 기능이 실행되지 않습니다?
내 답변을 찾았을 수도 있습니다 : http://stackoverflow.com/questions/35111367/test-that-a-function-calls-another-function-in-an-es6-module-with-sinon-js – montrealist