I am trying to test some javascript code (BackBone View) using jasmine
Here is the function within the defined BackBone view I am trying to test:
var aView = Backbone.View.extend({
events: {
'click #btn': 'update'
}
update: function(e){
e.preventDefault();
$.ajax({
....
});
}
});
So, to test the function I am trying to call the function and then spyOn $.ajax to see if it was called with appropriate url. But, the problem is I cannot pass the event into the function so that it carries out the ajax.
Here's the jasmine code block:
it("tests update ajax", function() {
spyOn($, "ajax");
//Call update function
this.aView.update(this.aView.$("#btn").trigger("click"));
expect($.ajax).toHaveBeenCalled();
});
Here's the error I am currently receiving:
TypeError: Object [object Object] has no method 'preventDefault'
I hope I have provided all the information necessary and the question is precise :)