vendredi 23 janvier 2015

How to make a unit test for ajax calls

I am a newbie in creating unit tests for JavaScripts. In my unit test I keep on getting "AssertError: expected "ok" but was [undefined] " as a result. Can any teach me how to do a unit test for ajax calls? Thanks. By the way, I'm using JsTestDriver for testing my unit tests.


Here's my source file:



function getReport(m, y)
{
$.ajax({
url: "url/to",
data: {
m:m,
y:y
},
dataType: 'json',
success:function (res) {
return res;

}
});


}


Here's my test file:



TestCase("Report", {

"test get report": function () {
assertEquals("ok", getReport(1, 2015));
}
});

Aucun commentaire:

Enregistrer un commentaire