QUnit testing AJAX calls

Viewed 32

I am trying to figure out how I would run a QUnit test on an AJAX call, I've searched on the web and also on here however, I'm still a little lost. I have an AJAX call which essentially just goes to the URL of pageAJAX.php, in here there is some PHP/MySQL code which just runs an INSERT query, of a page number and a module number, so the function savePgID, expects those 2 parameters.

script.js:

function savePgID(moduleID, pageID){
    $.ajax({  
        url: "pageAJAX.php",  
        method: "POST",   
        data: {moduleID:moduleID, pageID:pageID},
        dataType: 'json', //ajax to expect JSON data type
      });
  }

unit-tests.html:

Qunit.test("Testing AJAX call", savePgID(moduleID, pageID) {
$.ajax = function() {
    equals(pageAJAX.php);
    options.success("Hello");
}
equal("Hello");
});

Completely lost and unsure how to run a QUnit test on an AJAX call. any guidance at all? Obviously I wouldn't actually want to alter or modify the AJAX call by testing it.

0 Answers
Related