2016-11-15 1 views
0

나는이 간단한 테스트를 작동 시키려고합니다.간단한 인수를 사용하여 예상합니다

let querySpy = sinon.spy(db.query); 

querySpy.expects().once().withArgs(`USE myDatabase`); 

메서드에 스파이를 넣으려고합니다. 특정 인수를 사용하여 한 번 호출하면됩니다. 더 쉽게 말한 것입니다.

db에 스파이를 넣을 수 없으며 결과는 TypeError: Attempted to wrap undefined property undefined as function (개체 임)입니다. 내가 찾고 있어요

: https://gist.github.com/yoavniran/1e3b0162e1545055429e#sinon-chai

은 내가 calledOnceWith 방법을 찾을 수 없습니다. 그것이 존재합니까?

답변

0

args을 사용하여 함수에 전달 된 인수를 확인할 수 있습니다.

sinon.spy(db, "query"); //spy on existing method  
expect(db.query.calledOnce).to.be.true; //verify is called once 
const args = db.query.getCalls()[0].args; //get the arguments 
expect(args[0]).to.equal(`USE myDatabase`); //verify the arguments. 

이것은 args를 검증하는 한 가지 방법입니다.

관련 문제