I'm a newbie when it comes to jasmine and I'm trying to figure out how to verify if a specific node is present in the ajax response. Currently, I'm using grunt to run jasmine from the command line and have successfully tested if a function is called after an Ajax request returns. Here's a snippet of my code:
describe("Ajax call test.", function () {
it("should execute the callback function on success", function () {
spyOn($, "ajax").and.callFake(function(options) {
options.success();
});
var callback = jasmine.createSpy();
getSampleResponse(callback);
expect(callback).toHaveBeenCalled();
});
function getSampleResponse(callback){
$.ajax({url: "template/sample.json", dataType:"text", success:function(res){
callback();
}
});
}
});
This is what my sample.json file looks like:
{
success: {
"numSearches":5,
"data":[
{title:'search title 1', count:1},
{title:'search title 2', count:1},
{title:'search title 3', count:1},
{title:'search title 4', count:1},
{title:'search title 5', count:1}
]
}
}
I'm looking for a way to check if the response includes success.numSearches using jasmine. Any help would be greatly appreciated. Thanks!