이것은 또한 jQuery를 방법의 체인에 감시 할 수 있습니다 또 다른 방법입니다 - 알아 내기 위해 나에게 오랜 시간이 걸렸습니다. 예에서
, 나는 이메일 필드가
//set up stub and spy
const valSpy = sandbox.spy();
const jQueryStub = sandbox
.stub($.prototype, "find") // this prototype is important
.withArgs("input[name=email]")
.returns({ val: valSpy });
// call function under test
learnerAlreadyAccepted(inviteDoc);
// check expectations
expect(jQueryStub).to.have.been.called; // not really necessary
expect(valSpy).to.have.been.calledWith("");
을 삭제하고 테스트중인 기능 (약)입니다하는지 테스트하는 것을 시도하고있다 : 완벽하게 작동
learnerAlreadyAccepted = function(doc) {
$("form").find("input[name=email]").val("");
}
감사합니다! – Diskdrive
'stub (obj, 'meth', fn)이 제거되었습니다. 문서 ' –
을 참조하십시오. 시몬이 제안하는 내용을 추가하는 것이 유용합니다 : sandbox.stub (obj,'meth '). 대신에 callsFake (fn) 함수를 스텁하기 위해서. 함수가 아닌 값을 스텁하기 위해 대신 sandbox.stub (obj, 'meth'). value (fn)를 사용하십시오. – keligijus