I have a function that loads a template and I want to check the correct url.
Since I cannot find any information other than tracking ajax calls, I assume this is the same for calls .load(). I am using Jasmine 2.4.1
Function
function templateLoader() {
var templateURL = '/path/to/template.html';
$('#myElement').load(templateURL, function(response, status, xhr) {
if (status === "error") {
common.templateError(templateURL, xhr);
} else {
ns.successFunction();
}
});
}
Jasmine test
var templateURL = '/path/to/template.html';
spyOn($('#myElement'), "load");
templateLoader(); // call the function
expect($('#myElement').load.calls.mostRecent().args[0]["url"]).toEqual(templateURL);
When I run this test, I get the following error:
TypeError: unable to read property "mostRecent" from undefined
Is there any other way to do this? I also want to verify that the success function is being called, but until you can verify the URL is correct, I cannot do this.
source
share