Jasmine과 Sinon을 사용하여 Backbone.js 앱을 테스트하고 있습니다. 버튼 클릭을 클릭하면 Model의 save() 메서드가 호출되고 뷰의 el 요소에 메시지를 추가하는 success 콜백을 처리하는지 확인하려고합니다. 모델의 성공 콜백을 트리거하기 위해 sinon 서버를 가져 오는 데 문제가 있습니다.Backbone.js 테스트 Sinon을 사용하여 저장 성공 콜백을 호출하지 않음
Heres 전에 beforeEach의 변수는 before입니다. beforeEach의 변수는 모두 describe 함수에서 var 범위입니다.
beforeEach(function(){
server = sinon.fakeServer.create(); //create the fake server
server.respondWith([200, { "Content-Type": "text/html", "Content-Length": 2 }, "OK"]); //fake a 200 response
loadFixtures('signup_modal.html'); //load the fixture
element = $("#signupModal");
specSignUp = new SignUp();
signUpView = new SignUpView({model : specSignUp, el: $("#signupModal")});
});
그리고이 같은 실제 시험이 모습입니다 : 이것의 구현을 구축을 위해 노력하는 동안 내가 성공 콜백이 트리거 beign 것을 나에게 보여주기 위해 간단한 콜백 메소드를 생성
it("Should call send request",function(){
element.find("#signupButton").trigger('click'); //click the button which should trigger save
server.respond(); //fake the response which should trigger the callback
expect(element).toContain("#message");
});
:
sendRequest: function(){
console.log("saving");
this.model.save(this.model.toJSON(),{success: function(data){
console.log("success");
iris.addMessage(this.$("#messageContainer"),"Thank you");
}});
}
콘솔을 실행하면 "저장"되지만 성공 콜백이 호출되지 않습니다.
오류 콜백이 호출 되었습니까? – abraham
아 하! 오류가 발생했습니다! 나는 그걸 찾지 않을 거라 생각 했어. – bittersweetryan